iwan
iwan

Reputation: 7569

replace text in UNIX SED

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!

Upvotes: 1

Views: 1455

Answers (2)

cmbuckley
cmbuckley

Reputation: 42458

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>

Upvotes: 1

Ray Toal
Ray Toal

Reputation: 88378

The invocation you want is

sed -e 's/param1=.*/param1=abc/' text1.txt

Upvotes: 1

Related Questions