Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 May 2002 13:11:47 +0100
From:      Ceri Davies <setantae@submonkey.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:  <20020531121147.GA17428@submonkey.net>
In-Reply-To: <20020531130029.B28925@dogma.freebsd-uk.eu.org>
References:  <20020531130029.B28925@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, May 31, 2002 at 01:00:29PM +0100, j mckitrick wrote:
> 
> 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?

Do you end up with a zero length file ?

I *think* this is because the shell truncates file1 before calling sed, so
that all sed has to work with is an empty file.

I'm probably wrong though.

Ceri

-- 
you can't see when light's so strong
you can't see when light is gone

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?20020531121147.GA17428>