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

Trix Farrar trix at basement.net
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
> 


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


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 basement.net                   (` o-o ')   http://www.basement.net/
-----------------------------------ooO-(_)-Ooo--------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20071211/6c16a8a7/attachment.pgp


More information about the freebsd-questions mailing list