tags:

views:

80

answers:

1

hi all

I use the following sed command in UNIX Solaris

From SOLARIS machine

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

can some one have idea what the illegal option in Solaris (in place "-i" option in linux I need other option in Solaris with the same effect)

lidia

+1  A: 

You'll need to replicate -i's behavior yourself by storing the results in a temp file and then replacing the original file with the temp file. This may seem inelegant but that's all sed -i is doing under the covers.

sed '$ s/OLD/NEW/g' test > test.tmp && mv test.tmp test

If you care you could make it a bit more robust by using mktemp:

TMP=$(mktemp test.XXXXXX)
sed '$ s/OLD/NEW/g' test > "$TMP" && mv "$TMP" test
John Kugelman
maybe other option from awk I cant to move the file to other file
lidia
Any command that modifies a file "in place" is actually doing this make-copy-move-copy shuffle. Except for certain special cases you can't modify a file in place. If `mv` doesn't work perhaps `cp` will.
John Kugelman