home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!acorn!ixi!ixi!pd
- From: pd@x.co.uk (Paul Davey)
- Newsgroups: comp.unix.programmer
- Subject: Re: NAWK - ?Diff. printf output order when using a pipe.
- Message-ID: <PD.92Jul28131139@herts.x.co.uk>
- Date: 28 Jul 92 13:11:39 GMT
- References: <1992Jul26.033811.21614@nsisrv.gsfc.nasa.gov>
- <1992Jul26.221156.12144@nsisrv.gsfc.nasa.gov>
- Sender: paul@x.co.uk (Paul Davey)
- Organization: IXI Ltd.
- Lines: 65
- In-Reply-To: merritt@climate.gsfc.nasa.gov's message of 26 Jul 92 22:11:56 GMT
-
- >>>>> On 26 Jul 92 22:11:56 GMT, merritt@climate.gsfc.nasa.gov (John H. Merritt) said:
-
- John> In article <1992Jul26.033811.21614@nsisrv.gsfc.nasa.gov>, merritt@climate.gsfc.nasa.gov (John H. Merritt) writes:
- John> |> Explain why the following 'nawk' program produces:
- John> [ output deleted ]
-
- John> Already there is misunderstanding about what I want in the way of answers.
- John> I want a solution to getting the same output when seeing the output
- John> at the terminal or redirecting it to a file.
- John> I WANT THE PIPE TO REMAIN.
-
- Then your solution is to pipe everything through the pipe and it will
- come out at the same time. (Unfortunately you don't want to sort your
- begin and end parts though.)
-
- Your problem is illustrated here as a data flow diagram
-
- BEGIN and END ----------> OUTPUT1
- / \
- data -> [awk] > terminal output
- \ MIDDLE --------> [cat] -> OUTPUT2 /
-
- As soon as you have two processes (when awk forks the cat process as a
- child) the branches get out of step.
-
- Sort will take a long time to run as it has to read all its input
- before starting to output.
-
-
- John> If there is something like 'fflush' in AWK, that would be great.
-
- There isn't. Besides awk isn't producing the output of sort.
-
- John> So far 'close' was the closest thing I found, but the exact syntax eludes
- John> me -- if it is the right thing at all.
-
- That lets you close a file, but I don't think you can close a pipe.
-
- I think you will have to settle for three lots of output, (BEGIN,
- MIDDLE and END say) and join them together when the all processes have
- exited.
-
- Awk might exit before the cat or sort pipeline has however, so you
- must move the pipe outside of awk.
-
- Make your awk program do this
-
- BEGIN do begin stuff > begin.tmp
-
- MIDDLE do middle stuff to standard out
-
- END do end stuff > end.tmp
-
-
- Then run it like this
-
- nawk -f awkfile | sort > sort.tmp && cat begin.tmp sort.tmp end.tmp > finaloutput
-
-
- John> --
- John> \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
- John> John H. Merritt --> merritt@climate.gsfc.nasa.gov
- John> "I am generally intolerant of ignorance,
- John> but I have made an exception in your case."
-
-
-
-
- --
- Regards, pd@x.co.uk IXI Ltd.
- Paul Davey pd@ixi.uucp 62-74 Burleigh St.
- ...!uunet!ixi!pd Cambridge, U.K.
- "These _are_ interesting times" +44 223 462 131 CB1 1OJ
-