[TAG] More on filtering in-place
Kapil Hari Paranjape
kapil at imsc.res.in
Thu Apr 15 10:09:28 MSD 2004
On Wed, Apr 14, 2004 at 04:31:42PM -0600, Jason Creighton wrote:
> On Wed, 14 Apr 2004 20:42:59 +0100,
> Geoff Clare <lgtag20040414 at gclare.org.uk> wrote:
> > I read through your discussion of filtering in-place in issue #101
> > and was surprised that nobody mentioned this method:
> > filter < file 1<> file
> Hmm, Look at this:
> What's happened here is that the output from the filter is not as big as
> the file itself, so there's "leftover" data hanging around if you're
> (for example) removing things from the file. This could cause problems
> in some cases.
Actually, this is a problem with my original "solution" as well.
> But I'm curious: How does this work at all? What, exactly, does
> [it] tell the shell?
'< file' says open "file" in read mode and call it file-descriptor 0 (=stdin)
'1<> file' says open "file" in read/write mode (means notrunc open)
and call it file-descriptor 1 (=stdout)
(For more details see Jay's explanation in the April 2004 issue of LG).
I think Geoff's solution is "correct" to the extent that the original
solution was. When I asked the question I was thinking of filters like
"rot13" or other encryption(*) techniques that do not change the length of
The other solutions given using "buffer" or "perl" might work with
filters that reduce file size.
(*) I think rot13 *is* called an encryption technique by some
companies selling e-Books and so on! (Ref: Skylarov case)
More information about the TAG