sam
sam

Reputation: 655

shell sed to replace a special character in a text file but unable to replace it

I am trying to replace sam_18 with sam in a text file but it doesnt produce the correct result.

sed -i -e 's/sam_18/sam/g'

It doesnt produce any output. I am a bit confused if it is considering '_' in between as a special character. Any help?Thanks

Upvotes: 0

Views: 62

Answers (1)

vlxm
vlxm

Reputation: 68

Option -i requires a file (at least) to perform the in-place substitution:

sed -i -e 's/sam_18/sam/g' myfile

If no file are provided, sed reads from the standard input (or an input pipe). You cannot use -i in that case. You would then do something like:

cat myfile | sed -e 's/sam_18/sam/g' > newfile

Upvotes: 1

Related Questions