psm@manta.NOSC.MIL (Scot Mcintosh) (05/27/89)
Thnaks to all who responded to my query about cascading pipes in awk (which soon became a discussion of how to convert text to uppercase in awk). The following submission is my favorite, because it's applicable to any kind of filter, not just tr. It also nicely illustrates the use of some awk features that were a little hazy to me even after reading the book. BEGIN { outcmd = "tr '[a-z]' '[A-Z]' >foobar" } { print $1 | outcmd } END { close(outcmd) while (getline x < "foobar") print x; }
lukas@ihlpf.ATT.COM (00771g-Lukas) (06/01/89)
In article <821@manta.NOSC.MIL> psm@manta.nosc.mil.UUCP (Scot Mcintosh) writes: >BEGIN { > outcmd = "tr '[a-z]' '[A-Z]' >foobar" > } > { > print $1 | outcmd > } >END { > close(outcmd) > while (getline x < "foobar") > print x; > } There is no real need to use file "foobar" (unless you want it). This will also work, and save some complexity: BEGIN { outcmd = "tr '[a-z]' '[A-Z]'" } { print $1 | outcmd } If you wanted "foobar", you could tack " | tee foobar" on the end of outcmd. To get even simpler, you could get rid of outcmd completely with { print $1 | "tr '[a-z]' '[A-Z]'" } -- John Lukas att!ihlpf!lukas 312-510-6290