Mods to tee...

ajs ajs at hpfcla.UUCP
Fri Jan 18 11:34:00 AEST 1985


> Basically the mods allow tee to accept shell pipeline commands as
> descriptors to copy stdin to in addition to regular files...

I hate to tell you this, but you didn't have to change tee to do it.
(I hate to say so because (1) the proper solution is obscure and (2) I
almost made the same changes myself before discovering it.)  (And I'll
tell you right here in net.sources, because this information just might
prevent you from writing some unnecessary sources...)

Anyway, awk(1) is already a very nice pipe splitter:

	awk '{ print | "first-pipeline"; print }' | second-pipeline

You can do more than just split the data; you can also manipulate it in
various wonderful ways as it goes through.  You can set an awk variable
to "first-pipeline", then reference it in several places:

	awk '{ ...; print "test" x | cmd; ...; print y | cmd; ...}'

and only one instance of the pipeline will be created, to receive all
the data in the order printed.  You can even have awk write a shell
script on the fly!  How?  Make cmd = "sh", and away you go.

Why would you do that?  Well, for one thing, it's a very nice way to,
say, read a data file and mail various sections to various different
people.  (Hint:  Use awk to pipe a shell script to "sh", which consists
of a series of here-documents, surrounded by braces, piped to mail
commands.  For testing, set cmd = "cat > t" and look at file t
afterwards to see what sh would have executed.)

Awk:  It's Not Just Another Ugly Program

Alan Silverstein, Hewlett-Packard Fort Collins Systems Division, Colorado
{ihnp4 | hplabs}!hpfcla!ajs, 303-226-3800 x3053, N 40 31'31" W 105 00'43"



More information about the Comp.sources.unix mailing list