1

I have text1.txt that contains

<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>
     param1=<this can be any value - no hardcoded>
<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>

And I would like to replace this part this can be any value - no hardcoded with abc

What should be the right SED command? Note that due to environment restriction i don't have the flexibility to use any language such as perl, python, or ruby ~ and can only use Unix command. And no hardcoded except for param1

Thanks a lot in advance!

iwan
  • 7,269
  • 18
  • 48
  • 66

2 Answers2

1

The invocation you want is

sed -e 's/param1=.*/param1=abc/' text1.txt
Ray Toal
  • 86,166
  • 18
  • 182
  • 232
  • This might change all the sample values in comment. No? – Shiplu Mokaddim Apr 10 '12 at 08:33
  • If you mean that the six-character sequence `param1=` will always have the rest of the characters on its line repleced with `abc` even if it appears in a "comment" then yes. But the OP never said anything about comments. – Ray Toal Apr 10 '12 at 08:36
1

It sounds like you want something like s/<.\+>$/<abc>/:

$ cat test1.txt

<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>
     param1=<this can be any value - no hardcoded>
<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>

$ sed 's/<.\+>$/<abc>/' test1.txt

<abc>
<abc>
     param1=<abc>
<abc>
<abc>
cmbuckley
  • 40,217
  • 9
  • 77
  • 91