Redirecting to Multiple Locations with tee


Redirecting to Multiple Locations with tee

Suppose you just updated your address book file and want to send it to your boss in addition to putting it in your own files. You can, using tee, which redirects output to two different places (see Code Listing 6.19).

To redirect output to two locations with tee:

  • sort address.book new.addresses  | tee sorted.all | mail  boss@raycomm.com -s "Heres the  address book, boss - 

    At the shell prompt, use the tee command plus a filename in the middle of the pipe line to send the sorted information to that filename as well as to the standard output (which could, of course, be redirected to another filename). Here, we send the results of the sort to the sorted.all file and to standard output, where mail will take over and send the file to the boss. See Chapter 11 for more on fancy mail tricks.

Tee Time?

You might think of the tee command as being similar to a plumber's pipe joint that is, it takes stuff from one location and sends it out to two different places.


Code Listing 6.19. Use tee to send output to two different places at once.

[ejr@hobbes manipulate]$ sort address.book new.addresses | tee sorted.all | mail    boss@raycomm.com -s  "Heres the address book boss" - [ejr@hobbes manipulate]$ 




Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net