2

If I have:

foo
bar

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

foo-bar

..what's the syntax?

I'm trying to use:

system_profiler SPMemoryDataType | awk '/Type/ {print $2} /Speed/ {print $2}'|sed 's/\r$/a\"-"/'

to output type-speed (ie DDR-1067).

1
  • 1
    If you don't get any sed/awk help here, there are plenty of other sites that address those unix tools explicitly, rather than by extension that a mac program is generating xml output. Just hop in the chat room if you need help selecting a destination or flag it for moderator help if you prefer.
    – bmike
    Commented Sep 15, 2011 at 20:25

2 Answers 2

1

Use this sed instead:

|sed '$!N;s/\n/ /' 

system_profiler SPMemoryDataType | awk '/Type/ {print $2} /Speed/ {print $2}'|sed '$!N;s/\n/ /'

output:

DDR3 1066
DDR3 1066
DDR3 1066
Empty Empty
2
  • How do you make it stop after the first line though? When I awk using the above command I get: DDR2-667 [carriage return] DDR2-667 I just want the first line.
    – user11315
    Commented Sep 23, 2011 at 21:29
  • Insert an ;exit after /Speed/ {print $2 ,so it would look like: .... /Speed/ {print $2;exit} .....
    – l'L'l
    Commented Sep 24, 2011 at 4:04
0

Awk can easily do this on it's own, like so:

system_profiler SPMemoryDataType | awk '/Type:/ {type=$2} /Speed:/ {speed=$2; printf "%s-%s\n", type, speed}'

You must log in to answer this question.

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