Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Dec 2007 17:46:38 -0600
From:      Trix Farrar <trix@basement.net>
To:        Halid Faith <maslak@ihlas.net.tr>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: How to replace two strings in a file in the same time with sed	command ?
Message-ID:  <20071211234633.GA3568@basement.net>
In-Reply-To: <001001c83c33$669b46b0$dc96eed5@ihlasnetym>
References:  <001001c83c33$669b46b0$dc96eed5@ihlasnetym>

next in thread | previous in thread | raw e-mail | index | archive | help

--OgqxwSJOaUobr8KG
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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;
>=20
> yy=3D"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
>=20
> When I run the script,  I get an error, due to using cut command
>=20


yy=3Dfile5
for i in `cat file1` ; do=20
    sed -e "s/old1/new1 $i/g" -e "s/old2/`cut -d, -f 1 ${yy}`/g" file2 > fi=
le3
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.

--=20
John D. "Trix" Farrar               __\\|//__               Basement.NET
trix@basement.net                   (` o-o ')   http://www.basement.net/
-----------------------------------ooO-(_)-Ooo--------------------------

--OgqxwSJOaUobr8KG
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)

iD8DBQFHXyFZUn6S0hqD4tsRAnaeAJ9jK5VhMkL2B5YMhXczsTL/PJwx9ACeJZJS
mNb+nIKnki2lqSmqbBS0Q+c=
=XWdW
-----END PGP SIGNATURE-----

--OgqxwSJOaUobr8KG--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071211234633.GA3568>