TheWaterProgrammer
TheWaterProgrammer

Reputation: 8259

How can I avoid creation of the extra file with `-e` while using the sed tool in a shell script?

I am using sed command in a shell script to edit & replace some file content of an xml file in a osx(unix) environment. Is there some way I can avoid sed creating the temporary files with -e ? I am doing the following in my script to edit a file with sed.

sed -i -e 's/abc/xyz/g' /PathTo/MyEditableFile.xml

Above sed command works great but creates an extra file as /PathTo/MyEditableFile.xml-e

How can I avoid creation of the the extra file with -e there ?

I tried some options like setting a temporary folder path to sed so that it creates the temporary file in /tmp/. Like so:

sed -i -e 's/abc/xyz/g' /PathTo/MyEditableFile.xml >/tmp

But doesnt seem to work

Upvotes: 1

Views: 1236

Answers (1)

heemayl
heemayl

Reputation: 42107

As you are editing the file in place (-i), OS X sed requires a mandatory backup filename.

You can use -i "" to get around this:

sed -i "" -e 's/abc/xyz/g' /PathTo/MyEditableFile.xml

Upvotes: 4

Related Questions