How to replace two strings in a file in the same time with sed command ?

Trix Farrar trix at
Tue Dec 11 15:46:48 PST 2007

On Tue, Dec 11, 2007 at 10:21:22PM +0200, Halid Faith wrote:
> Ok
> But I have another problem,
> I couldn't use any command  interior of sed command. That's to say I have a
> script;
> yy="file5"
>  for i in `cat file1`;
>  do
>  sed -e 's/old1/new1\ \'$i'/g' -e 's/old2/'cut -d, -f 1 ${yy}'/g'   file2 >
> file3
>  done
> When I run the script,  I get an error, due to using cut command

for i in `cat file1` ; do 
    sed -e "s/old1/new1 $i/g" -e "s/old2/`cut -d, -f 1 ${yy}`/g" file2 > file3

I changed the single-quotes to double-quotes so that they can have
their variables interpreted.  The problem with this loop is that, at
each iteration, file3 will be overwritten.

John D. "Trix" Farrar               __\\|//__               Basement.NET
trix at                   (` o-o ')
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url :

More information about the freebsd-questions mailing list