Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sundc!texsun!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions Subject: Re: Narly Nawk Script Message-ID: <110273@convex.convex.com> Date: 11 Dec 90 02:27:56 GMT References: <4255@exodus.Eng.Sun.COM> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 59 In article <4255@exodus.Eng.Sun.COM> bm@bike2work.Eng.Sun.COM (Bill Michel) writes: :I'm working on a shell script that makes extensive use of (n)awk. : :The general layout is as follows : :nawk ' { : process a bunch of text, and append it to the variable "string" :} :END { : print string :} :' $* | :nawk ' :{ :do some more processing :}' | : :nawk ' :{ :do some more processing and send the output to a file :} The data is going down the pipe to the next awk in the pipeline. I'd try really hard if I were you to make this work in just one script if you possibly can. Otherwise, you will be slowed down a great deal. If you can't do that, you might consider using perl instead, which is something like nawk with a built-in fork (plus considerably more). In particular, it supports spawning children and communicating to them through shared file descriptors without having to know about how pipe() calls work. For example: if (open(HANDLE, "|-")) { # parent code writes to HANDLE } else { # child code just reads from STDIN per usual } or else: if (open(HANDLE, "-|")) { # parent code reads from HANDLE } else { # child code just writes to STDOUT per usual } You can also play more elaborate games using explicit pipe() calls. This does sound to me like an application where perl might be more applicable than awk. You can even use a2p awk-to-perl translator to get started. I can't really say though without seeing the script. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "With a kernel dive, all things are possible, but it sure makes it hard to look at yourself in the mirror the next morning." -me