Date: Fri, 31 May 2002 14:16:21 +0200 From: "Patrick O'Reilly" <bsd@perimeter.co.za> To: "j mckitrick" <jcm@FreeBSD-uk.eu.org> Cc: <freebsd-questions@FreeBSD.ORG> Subject: Re: Why does 'sed' delete my input file? Message-ID: <028601c2089c$fd7eef30$b50d030a@PATRICK> References: <20020531130029.B28925@dogma.freebsd-uk.eu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
----- Original Message -----
From: "j mckitrick" <jcm@FreeBSD-uk.eu.org>
> This is a simple question, but I can't find the answer. The
Daemonnews
> article that seems to answer it is missing the graphics with the
> screenshots.
>
> If I want to replace all occurrences of 'foo' in a file, this is what
I
> tried:
>
> sed s/foo/bar/g file1 > file1
>
> But this deletes (overwrites?) the contents of the file. What did I
do
> wrong?
>
The shell will open the file for output first (thereby emptying it).
Try this:
# sed s/foo/bar/g file1 > /tmp/x && mv /tmp/x file1
Regards,
Patrick O'Reilly.
___ _ __
/ _ )__ __ (_)_ __ ___ _/ /____ __
/ __/ -_) _) / ~ ) -_), ,-/ -_) _)
/_/ \__/_//_/_/~/_/\__/ \__/\__/_/
http://www.perimeter.co.za
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?028601c2089c$fd7eef30$b50d030a>
