Date: Fri, 31 May 2002 14:13:52 +0200 From: Miguel Mendez <flynn@energyhq.homeip.net> To: j mckitrick <jcm@FreeBSD-uk.eu.org> Cc: freebsd-questions@freebsd.org Subject: Re: Why does 'sed' delete my input file? Message-ID: <20020531141352.A66831@energyhq.homeip.net> 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 %2B0100 References: <20020531130029.B28925@dogma.freebsd-uk.eu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020531141352.A66831>