views:

433

answers:

7

i need to redirect a output of a command to two files say file1 and file2 file1 is a new file and file2 is already existing file where i need to append the output i have tried

This is not giving the expected results:

command > file1 > file2
+2  A: 

For Windows (cmd.exe):

command > file1 & type file1 >> file2
Tomalak
+3  A: 

You are looking for the tee command.

$ echo existing >file2
$ date | tee file1 >> file2
$ cat file2
existing
Mon Mar  9 10:40:01 CET 2009
$ cat file1
Mon Mar  9 10:40:01 CET 2009
$
phihag
+2  A: 

Assuming you're on a Linux-like system, try

command | tee file1 >> file2

tee splits the output stream and sends it to two destinations.

David Zaslavsky
A: 

In Linux:

u can do this

command | tee file1 >> file2

serioys sam
No offense, but I don't think "u" is a word. Please use proper English in your answers, Stack Overflow is not a forum. Thank you! :-)
Tomalak
+1  A: 

In PowerShell use tee-object (or its tee alias)

command | tee first-file | out-file second-file

Can also tee to a variable (e.g. for further processing).

Richard
A: 

Tee

TPipe

Dutow
A: 

thanks all ... i got it

Please accept the answer that helped you most. And use the answers section for answers only, comments like this one - that's what the comments feature is for.
Tomalak