From owner-freebsd-questions Fri May 31 5:13:53 2002 Delivered-To: freebsd-questions@freebsd.org Received: from energyhq.homeip.net (213-97-200-73.uc.nombres.ttd.es [213.97.200.73]) by hub.freebsd.org (Postfix) with ESMTP id 5D42F37B400 for ; Fri, 31 May 2002 05:13:47 -0700 (PDT) Received: by energyhq.homeip.net (Postfix, from userid 1001) id 3F09E3FC5D; Fri, 31 May 2002 14:13:52 +0200 (CEST) Date: Fri, 31 May 2002 14:13:52 +0200 From: Miguel Mendez To: j mckitrick Cc: freebsd-questions@freebsd.org Subject: Re: Why does 'sed' delete my input file? Message-ID: <20020531141352.A66831@energyhq.homeip.net> Mail-Followup-To: j mckitrick , freebsd-questions@freebsd.org References: <20020531130029.B28925@dogma.freebsd-uk.eu.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="SUOF0GtieIMvvwua" Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20020531130029.B28925@dogma.freebsd-uk.eu.org>; from jcm@FreeBSD-uk.eu.org on Fri, May 31, 2002 at 01:00:29PM +0100 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --SUOF0GtieIMvvwua Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 31, 2002 at 01:00:29PM +0100, j mckitrick wrote: Hi, > If I want to replace all occurrences of 'foo' in a file, this is what I > tried: >=20 > sed s/foo/bar/g file1 > file1 >=20 > But this deletes (overwrites?) the contents of the file. What did I do > wrong? It's not sed that does that. Note that you are redirecting the output with '>', so the shell truncates file1. However, there are other ways to do that. sed will soon have a -i option soon, but in the meantime you could just: sed -e 's/foo/bar/g' file1 > file1.tmp && mv file1.tmp file1 or perl -pi -e 's/foo/bar/g' file1 Cheers, --=20 Miguel Mendez - flynn@energyhq.homeip.net GPG Public Key :: http://energyhq.homeip.net/files/pubkey.txt EnergyHQ :: http://www.energyhq.tk FreeBSD - The power to serve! --SUOF0GtieIMvvwua Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iD8DBQE892kAnLctrNyFFPERAjNhAJ40KPFyPdoy1N7xw1xl1vHwSzcFigCbBUeh OPuBXXHGQ55b1gzbrIWPRTU= =3CJD -----END PGP SIGNATURE----- --SUOF0GtieIMvvwua-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message