Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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).

share|improve this question
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 Sep 15 '11 at 20:25

2 Answers 2

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}'
share|improve this answer

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
share|improve this answer
    
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 Sep 23 '11 at 21:29
    
Insert an ;exit after /Speed/ {print $2 ,so it would look like: .... /Speed/ {print $2;exit} ..... –  l'L'l Sep 24 '11 at 4:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.