Narly Nawk Script
Tom Christiansen
tchrist at convex.COM
Tue Dec 11 13:27:56 AEST 1990
In article <4255 at exodus.Eng.Sun.COM> bm at 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 at 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
More information about the Comp.unix.questions
mailing list