I found this post: Variations of sed between OSX and GNU/Linux
SED without backup file
Which provided the solution for using sed -i on Mac OSX such that it does not create a back file on a search and replace command.
E.g., Note the singlequote space singlequote after -i option to specify a zero length extension:
sed -i ' ' 's/foo/|bar/g' test.html
My problem - this DOES create a backup file for me, and it gives the backup file the same name as my input file, "test.html"
I need to run a search/replace on many files, and I don't want backup files.
Here's my actual command:
sed -i ' ' "s|research/projects/vertebrategenome/havana/|science/groups/vertebrate-annotation|g" test2.html
Where I get a backup file called "test2.html"
On the mac, you get the BSD version of sed. It required to include a null string as an argument to -i. Note, on linux, it is happy to accept the -i with no extension.
On Linux:
sed -i 's|StringToReplace|ReplacedString|'
on MacOSX/*BSD
sed -i '' 's|StringToReplace|ReplacedString|'
Note, you want a nullstring ('') not a blank(' ').
The best way I have found to have the same script work on both Linux and Mac is to:
sed -i.bak -e 's/foo/bar/' -- ${TARGET}
rm ${TARGET}.bak
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With