0

To change all occurences of the string foo to bar in all files in a directory I use

sed -i -- 's/foo/bar/g' *

Found that here

But I also want to change NAME to name etc. I tried,

sed -i -- 's/foo/bar/g' * ; sed -i -- 's/NAME/name/g' *

This creates new files. How can I get this command to rewrite the original file with foo replaced with bar and also NAME replaced with name and then there would be other replacements, without creating new files?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
ofey
  • 111

1 Answers1

8

You can give several expressions to sed in one invocation:

sed -e 'expr' -e 'expr' -e ...

In your case:

sed -e 's/foo/bar/g' -e 's/NAME/name/g'

The expressions will be applied to each line of input in succession, from left to right.

Kusalananda
  • 333,661