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
The > symbol is used to redirect output by taking the output from the command on the left and passing as input to the file on the right.
You can use cat with redirection to append a file to another file. You do this by using the append redirection symbol, ``>>''. To append one file to the end of another, type cat, the file you want to append, then >>, then the file you want to append to, and press <Enter>.
The >> shell command is used to redirect the standard output of the command on the left and append (add) it to the end of the file on the right.
Redirecting output to Multiple files and screen: If you want to redirect the screen output to multiple files, the only thing you have to do is add the file names at the end of the tee command.
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
$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With