LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-14-2012, 10:29 PM   #1
tushar_pandey
Member
 
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105

Rep: Reputation: Disabled
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
 
Old 08-14-2012, 10:48 PM   #2
Refractor
Member
 
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Debian
Posts: 91

Rep: Reputation: 25
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.
 
1 members found this post helpful.
Old 08-15-2012, 03:32 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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.
 
1 members found this post helpful.
Old 08-15-2012, 05:51 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cat 6 Cat 5e cable question babbab Linux - Networking 1 04-07-2010 02:33 PM
cat olepholks Linux - General 10 09-21-2009 12:29 PM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
Using cat readline within cat readline while loop demxkn66 Programming 5 12-16-2007 05:10 PM
cat in asm/ cat --show-all option Tux Linux - Software 1 09-02-2006 09:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration