Ny alternative to the “sed -i” command in Solaris

sedsolaristext processing

I have a requirement in my project to replace some existing text in a file like foo with some other text like fooofoo:

abc.txt
name
foo
foo1

So I tried:

sed -i "s/foo/fooofoo/g" abc.txt

However I get this error:

sed: illegal option — i

I found in the manual that I have to use:

sed -i\ "s/foo/fooofoo/g" abc.txt

However this is not working either.

I found alternatives in perl and awk also but a solution in Solaris sed would be much appreciated.

I am using this version of bash:

GNU bash, version 3.2.57(1)-release (sparc-sun-solaris2.10)

Best Answer

Use ed. It's available on most platforms and it can edit your files in-place.
Since sed is based on ed the syntax for replacing patterns is similar:

ed -s infile <<\IN
,s/old/new/g
w
q
IN
Related Question