From owner-freebsd-questions@FreeBSD.ORG Tue Dec 11 23:46:47 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EAD1316A46B for ; Tue, 11 Dec 2007 23:46:47 +0000 (UTC) (envelope-from trix@basement.net) Received: from fran.basement.net (fran.basement.net [66.139.76.84]) by mx1.freebsd.org (Postfix) with ESMTP id C21D613C459 for ; Tue, 11 Dec 2007 23:46:47 +0000 (UTC) (envelope-from trix@basement.net) Received: from faith.basement.net (adsl-065-013-140-007.sip.bna.bellsouth.net [65.13.140.7]) by fran.basement.net (8.12.8/8.12.8) with ESMTP id lBBNkcLh011723; Tue, 11 Dec 2007 17:46:39 -0600 Received: from faith.basement.net (localhost [127.0.0.1]) by faith.basement.net (8.13.8/8.13.8) with ESMTP id lBBNkcTR003661; Tue, 11 Dec 2007 17:46:38 -0600 (CST) (envelope-from trix@basement.net) Received: (from trix@localhost) by faith.basement.net (8.13.8/8.13.8/Submit) id lBBNkcFp003660; Tue, 11 Dec 2007 17:46:38 -0600 (CST) (envelope-from trix@basement.net) X-Authentication-Warning: faith.basement.net: trix set sender to trix@basement.net using -f Date: Tue, 11 Dec 2007 17:46:38 -0600 From: Trix Farrar To: Halid Faith Message-ID: <20071211234633.GA3568@basement.net> Mail-Followup-To: Trix Farrar , Halid Faith , freebsd-questions@freebsd.org References: <001001c83c33$669b46b0$dc96eed5@ihlasnetym> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OgqxwSJOaUobr8KG" Content-Disposition: inline In-Reply-To: <001001c83c33$669b46b0$dc96eed5@ihlasnetym> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=0.1 required=5.0 tests=RDNS_DYNAMIC autolearn=no version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on fran.basement.net Cc: freebsd-questions@freebsd.org Subject: Re: How to replace two strings in a file in the same time with sed command ? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Dec 2007 23:46:48 -0000 --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--