procmail
[Top] [All Lists]

Re: cat foo | bar > foo (RE: Round Robin for email using Procmail)

2000-06-29 22:46:13
From schaefer(_at_)zanshin(_dot_)com  Thu Jun 29 12:37:45 2000

On Wed, 28 Jun 2000, Dallman Ross wrote:

After I said on the list yesterday that

    cat rrobinlist | sed > 's/^\([^,]*\),\(.*\)/\2,\1/' > rrobinlist

There looks to be an extraneous ">" in that sed command ...

Yes, thanks for catching it.  I pasted from mail, and I missed that
when I took the quotes out.

would not work (would null out the file after the redirect to the
file), I had private mail with the original author, Lee Howard,
who showed me that it does work for him.  I investigated, and
found out that he's right - as long as the environment setting for
noclobber is not turned on.

He's only right as long as the size of the file is less than the
size of the operating system buffer in the pipeline between cat and
sed (plus the size of the stdio or similar buffers used by cat and
sed, if any).  That is, it works only if "cat" can read the entire
file and pipe it through to sed before sed begins to produce any
output.

Ah.  Good analysis.  Thanks.

It's also highly dependent on the shell's implementation of
pipelines.  As it's the shell that opens the file for output before
starting sed, it could easily decide to do so before starting cat as
well.

As none of this should be relied upon, your original objection was
correct.  The only correct way to do the above for an arbitrarily
...............^^^^^
large file is somthing like


      sed 's/^\([^,]*\),\(.*\)/\2,\1/' < rrobinlist > rrtmp &&
      mv -f rrtmp rrobinlist

Which of course has a race condition unless you use it in a locking
recipe.

I continue to hate the word "only" when I see it refering to anything
UNIX-y. :-)  What about my sort kludge from yesterday? | sort -m -o file
works fine to preserve file and negate race conditions, I believe.  My
main objection to it is that it is such an obvious kludge.

-- 
D-Man


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>