You are not logged in.
Occasionally, I come across the need to pass the output of a single command to multiple others (without piping each to the next), so today, I wrote a [very] simple Bash script to accomplish the task. Piping the output of a command to `tree' is much like piping it to `tee', except `tree' allows you to execute multiple commands on the same output, rather than only writing to log files:
#!/bin/bash
#
# tree -- pipes the output of one command to >= 1 other
#
# Usage: command | tree 'command 1' 'command 2'
doc=$( cat - )
for arg in "$@"; do
bash -c "${arg}" <<EOF
${doc}
EOF
done
An example of its usage:
$ echo -e "1 2 3\n4 5 6" | tree 'grep 1' 'grep 4' "grep 1 | tee grep.log | awk '{print \$2}'"
1 2 3
4 5 6
2
$ cat grep.log
1 2 3
Though not elaborate, the script gets the job done.
Last edited by deltaecho (2009-03-10 20:34:01)
Dylon
Offline
the name is a little unfortunate. there is already a tree utility
cheers Barde
Offline
You could always call it "the Ukrainian Pipe"
(if you can't laugh at this, you either need to loosen up or make a point to follow (annual) current events)
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
the name is a little unfortunate. there is already a tree utility
cheers Barde
...so there is...
My conscience is clear, though, because I didn't know about it until after your post If the script creates a naming conflict, you may definitely rename it anything you please.
Dylon
Offline
You could always call it "the Ukrainian Pipe"
(if you can't laugh at this, you either need to loosen up or make a point to follow (annual) current events)
That was a good one
Dylon
Offline