Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 May 2002 09:47:20 -0700
From:      Matthew Hunt <mph@astro.caltech.edu>
To:        j mckitrick <jcm@FreeBSD-uk.eu.org>
Cc:        Benoit Lacherez <blacherez@ac-bordeaux.fr>, freebsd-questions@FreeBSD.ORG
Subject:   Re: Why does 'sed' delete my input file?
Message-ID:  <20020531094720.C34758@wopr.caltech.edu>
In-Reply-To: <20020531132211.A29199@dogma.freebsd-uk.eu.org>; from jcm@FreeBSD-uk.eu.org on Fri, May 31, 2002 at 01:22:11PM %2B0100
References:  <20020531130029.B28925@dogma.freebsd-uk.eu.org> <20020531141421.A72043@bisclavret.iris33.ac-bordeaux.f> <20020531132211.A29199@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, May 31, 2002 at 01:22:11PM +0100, j mckitrick wrote:

> | cat file1 | sed 's/foo/bar/g' > file1
> 
> Perfect!

I don't think that's guaranteed to work at all.  There's no assurance
that cat will have read then entire contents of file1 before the shell
opens it for writing.

wopr:~/tmp$ wc -l blah 
  164925 blah

wopr:~/tmp$ ls -l blah 
-rw-------  1 mph  mph  - 6807485 May 31 09:42 blah

wopr:~/tmp$ cat blah | sed 's/foo/bar/g' > blah

wopr:~/tmp$ ls -l blah
-rw-------  1 mph  mph  - 0 May 31 09:42 blah

My shell is bash.

-- 
Matthew Hunt <mph@astro.caltech.edu> * Eight lanes of shimmering cement from
http://www.pobox.com/~mph/           * here to Pasadena!

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?20020531094720.C34758>