Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to replace,

input.output.roomMAX[0]        to   input.output.room[0].MAX
input.output.roomMAX[1]        to   input.output.room[1].MAX
input.output.roomMIN[variable] to   input.output.room[variables].MIN

I am getting stuck on how to match things and reference them in the replacement. What argument do I give to sed?

share|improve this question

1 Answer 1

up vote 2 down vote accepted
sed 's/room\(MAX\|MIN\)\(\[[^]]*\]\)/room\2.\1/' inputfile

If you want to change "variable" to "variables" add another instruction:

sed 's/room\(MAX\|MIN\)\(\[[^]]*\]\)/room\2.\1/;s/variable/variables/' inputfile
share|improve this answer
    
Or: sed -r 's/room(MIN|MAX)(\[.*\])/room\2.\1/' with less escaping. –  slhck Jul 27 '12 at 7:41
    
@slhck: If your version of sed supports it (or -E for OS X). –  Dennis Williamson Jul 27 '12 at 7:43
    
Yeah. At some point I got used to not using BSD sed anymore and using gsed, on OS X at least. –  slhck Jul 27 '12 at 7:44

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.