Alternative to `sed -i` on Solaris

lidia picture lidia · Aug 26, 2010 · Viewed 44.2k times · Source

On Linux sed -i will modify the input files in place. It doesn't work on Solaris, though.

sed -i '$ s/OLD/NEW/g' test        
sed: illegal option -- i

What can I use in place of sed -i on Solaris?

Answer

Charlie B picture Charlie B · Nov 30, 2010

It isn't exactly the same as sed -i, but i had a similar issue. You can do this using perl:

perl -pi -e 's/find/replace/g' file

doing the copy/move only works for single files. if you want to replace some text across every file in a directory and sub-directories, you need something which does it in place. you can do this with perl and find:

find . -exec perl -pi -e 's/find/replace/g' '{}' \;