Discussion:
tee command
(too old to reply)
puzzlecracker
2008-08-06 22:35:21 UTC
Permalink
Can someone explain how tee command works. thanks
Lew Pitcher
2008-08-06 23:18:08 UTC
Permalink
On August 6, 2008 18:35, in comp.unix.shell, puzzlecracker
Post by puzzlecracker
Can someone explain how tee command works. thanks
The tee(1) ("man 1 tee") command copies everything from it's standard input
to both it's standard output, and to each file named in it's arguments.

So, the pipeline
echo "Hello there" | tee output_file | sed 's/there/here/'
will
echo the string "Hello there" to stdout, which is piped into tee's stdin
tee will copy the string "Hello there" to the file called output_file, and
to it's own stdout, which is piped into sed's stdin
sed will read it's stdin, change the first occurrence of the string "there"
to "here", and send all the read data to stdout
resulting in
the file output_file containing the string "Hello there", and
the string "Hello here" showing on the screen.

~/tmp $ ls
~/tmp $ echo "Hello there" | tee output_file | sed 's/there/here/'
Hello here
~/tmp $ ls
output_file
~/tmp $ cat output_file
Hello there
~/tmp $
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
Kenny McCormack
2008-08-07 12:18:23 UTC
Permalink
Post by Lew Pitcher
On August 6, 2008 18:35, in comp.unix.shell, puzzlecracker
Post by puzzlecracker
Can someone explain how tee command works. thanks
The tee(1) ("man 1 tee") command copies everything from it's standard input
to both it's standard output, and to each file named in it's arguments.
That's "What it does", not "how it works".
Please try again.
Bill Marcum
2008-08-07 13:51:49 UTC
Permalink
Post by Kenny McCormack
Post by Lew Pitcher
On August 6, 2008 18:35, in comp.unix.shell, puzzlecracker
Post by puzzlecracker
Can someone explain how tee command works. thanks
The tee(1) ("man 1 tee") command copies everything from it's standard input
to both it's standard output, and to each file named in it's arguments.
That's "What it does", not "how it works".
Please try again.
Read the source code.
Randal L. Schwartz
2008-08-07 23:35:40 UTC
Permalink
Kenny> That's "What it does", not "how it works".
Kenny> Please try again.

OK. "it works quite well".

But seriously, the question is ambiguous, so any possible answer is fair game.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
Barry Margolin
2008-08-08 04:05:28 UTC
Permalink
Post by Kenny McCormack
Post by Lew Pitcher
On August 6, 2008 18:35, in comp.unix.shell, puzzlecracker
Post by puzzlecracker
Can someone explain how tee command works. thanks
The tee(1) ("man 1 tee") command copies everything from it's standard input
to both it's standard output, and to each file named in it's arguments.
That's "What it does", not "how it works".
Please try again.
Its basic structure works something like this:

Open all the output files
while input is available
read some input from standard input
write it to standard output
for each output stream
write it to the output stream
Close all the output files
Exit
--
Barry Margolin, ***@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Loading...