help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Use stdin without tempfile


From: Peng Yu
Subject: Re: [Help-bash] Use stdin without tempfile
Date: Mon, 2 Dec 2013 08:30:45 -0600

> 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.

> and if your awk doesn't have fflush:
> printf %s\\n {1..30} | awk '{print > (NR<=10?p1:p2)}NR==10{system("")}'
> p1=>(sed 's/^/first /') p2=>(sed 's/^/second: /')
>
>
> Or the equivalent named pipe version:
>
> mkfifo p1 p1;sed 's/^/first /'  <p1 & sed 's/^/second: /' <p2 & printf %s\\n
> {1..30} | awk '{print > (NR<=10?"p1":"p2")}'
>
> or with sed:
> printf %s\\n {1..30} | sed -n  -e '1,10w '>(sed 's/^/first /') -e '11,$w
> '>(sed 's/^/second: /' >&2)
> mkfifo p1 p1;sed 's/^/first /'  <p1 & sed 's/^/second: /' <p2 & printf %s\\n
> {1..30} | sed -n -e '1,10w p1' -e '11,$ w p2'



-- 
Regards,
Peng



reply via email to

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