narzero
narzero

Reputation: 2299

Write output to two files, overwrite the first one, append to the second one

I want to write the output of a script to two files. Overwriting the first file but appending to the second one.

I'm currently doing:

echo Foo Bar | tee -a one.txt | tee -a two.txt

But this appends Foo Bar to both files.

Example:

Before

cat one.txt
#=> Bar Foo

cat two.txt
#=> Hello world

After

cat one.txt
#=> Foo Bar

cat two.txt
#=> Hello world
    Foo Bar

How do I do this with a single command?

Upvotes: 0

Views: 156

Answers (1)

stanleyxu2005
stanleyxu2005

Reputation: 8241

You are very close the answer already.

tee -a means to append. Without -a means to overwrite.

echo Foo Bar | tee one.txt | tee -a two.txt

Upvotes: 3

Related Questions