LinuxQuestions.org
Visit Jeremy's Blog.
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, 11: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, 11:48 PM   #2
Refractor
Member
 
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Slackware
Posts: 89

Rep: Reputation: 24
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, 04:32 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
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, 06:51 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:33 PM
cat olepholks Linux - General 10 09-21-2009 01:29 PM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 07:38 AM
Using cat readline within cat readline while loop demxkn66 Programming 5 12-16-2007 06:10 PM
cat in asm/ cat --show-all option Tux Linux - Software 1 09-02-2006 10:31 PM


All times are GMT -5. The time now is 11:04 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration