sed -i option is not working on solaris

Raj picture Raj · Nov 8, 2010 · Viewed 29.1k times · Source

I am using sed to replace a line with NULL in a file. The command i used is

sed -i "s/.*shayam.*//g" FILE

This is working fine in linux. shayam is replaced with blank in the FILE. But when i used this in solaris it is showing some error.

sed: illegal option -- i

How to use -i functionality of sed in solaris. Kindly help.

Answer

camh picture camh · Nov 8, 2010

The -i option is GNU-specific. The Solaris version does not support the option.

You will need to install the GNU version, or rename the new file over the old one:

sed 's/.shayam.//g' FILE > FILE.new && mv FILE.new FILE