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

I am trying to replace,

input.output.roomMAX[0]        to[0].MAX
input.output.roomMAX[1]        to[1].MAX
input.output.roomMIN[variable] to[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
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

You must log in to answer this question.

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