Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I have:


..and I'd like to awk/sed this to:


..what's the syntax?

I'm trying to use System Profiler on OS X 10.6.x:

system_profiler SPMemoryDataType | awk '/Type/ {print $2} /Speed/ {print $2}'

to output type-speed (ie DDR-1067). Haven't figured out how to do this using print or printf yet, might try to just grep instead..

share|improve this question

With tr:

tr '\n' '-'

Would that be enough? This replaces every newline with a comma.

With sed:

A prettier solution using sed:

sed -e N -e 's/\n/-/'

The N appends the newline to the pattern space according to the manpage:


Append the next line of input to the pattern space, using an embedded newline character to separate the appended material from the original contents. Note that the current line number changes.

With bash

Actually, bash can do what tr can do. Just for completeness:

while read l; do echo -n "$l-"; done

Here's a similar question on Stack Overflow: SED: How can I replace a newline (\n)?

share|improve this answer
awk 'BEGIN {ORS="-"} {print}'

Joins your data. What's inside the begin statement happens prior to reading the data. Here we define that the output record separator is -. Print prints the data.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .