[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Use stdin without tempfile

From: Pierre Gaston
Subject: Re: [Help-bash] Use stdin without tempfile
Date: Tue, 3 Dec 2013 09:10:11 +0200

On Mon, Dec 2, 2013 at 4:30 PM, Peng Yu <address@hidden> wrote:

> > you can perhaps use awk with process substitution like this:
> > printf %s\\n {1..30} | awk '{print > (NR<=10?p1:p2)}' p1=>(sed 's/^/first
> > /') p2=>(sed 's/^/second: /')
> In simple cases, the above works.
> > Or, if buffering is a problem:
> > printf %s\\n {1..30} | awk '{print > (NR<=10?p1:p2)}NR==10{fflush(0)}'
> > p1=>(sed 's/^/first /') p2=>(sed 's/^/second: /')
> But I'd imagine flushing might be necessary in certain cases. Is there
> a way to force out-of-order print even with simple/short input for
> debugging awk program? Thanks.

I'm not sure to understand your use case.
What the flush do in this case is making sure all the lines are sent to the
first sed, which print them immediately because it's connected to a
I'm not sure it is enough to guarantee the order, I think it 's not
impossible for the second sed to run before the first one even with this as
the process are not synchronized.

If you were the whole stdout to a file, you might also have problems with
the order of the result since the 2 seds would do buffering of their own.

Otherwise awk will print the lines in the  order it process them.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]