OrcunK
OrcunK

Reputation: 1

How to append a string near a particular string in a file?

I want to append a string after a particular string in a file but not into new line.

For example, I want to add two after =.

Before executing file:

one
two=
three
four
five

After executing file:

one
two=two
three
four
five

How can I do this with a sed command?

Upvotes: 0

Views: 91

Answers (1)

tink
tink

Reputation: 15238

Assuming you would like to do that in place:

sed -i 's/=/=two/' /path/to/file

That does a search & replace; the found equal gets replaced with =two.

Should you want to keep a backup of the original just add an extension right after the -i, e.g.

sed -i.bak 's/=/=two/' /path/to/file

Upvotes: 2

Related Questions