LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cat f_1 > f_2 > f_3 (https://www.linuxquestions.org/questions/linux-newbie-8/cat-f_1-f_2-f_3-a-4175422125/)

tushar_pandey 08-14-2012 10:29 PM

cat f_1 > f_2 > f_3
 
in f_1 :: hey , hi

but after cat f_1 > f_2 > f_3

f_1 = hey , hi
f_2 has nothing , why
f_3 = hey , hi

Refractor 08-14-2012 10:48 PM

I'm not really familiar with the input/output redirection mechanism so I can't say why the content is going into f_3 instead of f_2, but if you want to 'cat' the contents of f_1 to f_2 and f_3, you can use
Code:

cat f_1 | tee -a f_2 > f_3
tee is a command that writes (-a is for append in this case) input to the screen and into a specified file.

grail 08-15-2012 03:32 AM

Think of each > as a number (as it is assigned a file descriptor). Seeing as you used the same number both times, only the final file will receive the data. This is a simple definition.

David the H. 08-15-2012 05:51 AM

You can't redirect the same output to multiple files at the same time. There's only one stdout, so there's only one place it can go. Use tee, as shown above, to duplicate the output.

I believe in the above that the shell first sets up the "> f_2" redirection, then immediately replaces it with the "> f_3" redirection, clearing the first one.


All times are GMT -5. The time now is 07:01 AM.