How to redirect you o/p to many files at the same time.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to redirect you o/p to many files at the same time.
# 1  
Old 12-24-2009
How to redirect you o/p to many files at the same time.

How to redirect your o/p to many files without using for loop.

Code:
For example:-

1-echo "blablabla" > out01 OUT
2-echo "blablabla" 1>out01 1>OUT
3-echo "blablabla" 1>&out01 1>&OUT


the above code does not work!
in "1" only the o/p goes to out01
in "2" & "3" the o/p goes to OUT

appreciate any help in advance.
# 2  
Old 12-24-2009
The Z Shell has the multios option:

Code:
zsh-4.3.10[t]% print x >a >b >c
zsh-4.3.10[t]% head *
==> a <==
x

==> b <==
x

==> c <==
x

Or even:

Code:
zsh-4.3.10[t]% print y >>*     
zsh-4.3.10[t]% head *
==> a <==
x
y

==> b <==
x
y

==> c <==
x
y

With the other shells you should use the external command tee:

Code:
zsh-4.3.10[t]% bash -c 'echo z | tee a b c'
z
zsh-4.3.10[t]% head *
==> a <==
z

==> b <==
z

==> c <==
z

# 3  
Old 12-24-2009
Thanks radoulov it worked fine using tee but one problem how to eliminate the tee
o/p in below (red bold font).

Code:
bash-3.00$ bash -c 'echo z | tee a b c'
z
bash-3.00$head *
==> a <==
z

==> b <==
z

==> c <==
z

# 4  
Old 12-24-2009
Code:
tee a b c >/dev/null

Smilie
# 5  
Old 12-24-2009
Thanks a lot man it worked perfectly as expected.

SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

redirect time command output to file (cygwin bash)

I have set up a bash script to run a long list of things that I need to time. I would like to redirect the output of time to a file. I have set it up like, echo "Runtimes for servlet 4, 100K structures" > test_times.txt echo "" >> test_times.txt echo "runs where N=10" >> test_times.txt echo... (7 Replies)
Discussion started by: LMHmedchem
7 Replies

2. Shell Programming and Scripting

Redirect Output and Error in 2 different files

hi, i want to redirect my output & error if generated to two different files. I have written the code for redirecting the output, i dnt have ne idea how to go abt it for errors. I tried spooling which was given in one of the threads on this forum.But it didn't work.The script i wrote as a lot... (4 Replies)
Discussion started by: bankimmehta
4 Replies

3. Shell Programming and Scripting

How to Pull out multiple files from DB table and redirect all those files to a differetn directory?

Hi everyone!! I have a database table, which has file_name as one of its fields. Example: File_ID File_Name Directory Size 0001 UNO_1232 /apps/opt 234 0002 UNO_1234 /apps/opt 788 0003 UNO_1235 /apps/opt 897 0004 UNO_1236 /apps/opt 568 I have to... (3 Replies)
Discussion started by: ss3944
3 Replies

4. UNIX for Advanced & Expert Users

redirect to both file and std output at the same time

hello can some one please help me to redirect the output of a command to both std output and a file. this is little urgent. sridhar (2 Replies)
Discussion started by: send2sridhar
2 Replies

5. Shell Programming and Scripting

redirect files to a directory

i have some 2000 files and i want to redirect it to a dir after i give the command find . -mtime -15 -print it gives some 2000 files file1.DAT file2.DAT : : : file2000.DAT ------------------------------------------------------------------------how to redirect all these 2000 files... (2 Replies)
Discussion started by: ali560045
2 Replies

6. Shell Programming and Scripting

Real time log file redirect

Hi all, i would like to write the shell script program, it can monitor the access_log "real time" when the access_log writing the line contain "abcdef" the program will be "COPY" this line into a file named "abcdef.txt", do the same thing if the contain "123456" "COPY" it into a file named... (3 Replies)
Discussion started by: eric_wong_ch
3 Replies

7. UNIX for Dummies Questions & Answers

Redirect the Time result to a test file

I need to store process runtime into a file, currently the command i use was: time ls >> abc.txt however, this command store the executed result of ls into the txt file but not the time command result. Anyone know how to store the "time ls" result? Please advise me! Thanks in advance :) (5 Replies)
Discussion started by: mistella
5 Replies

8. UNIX for Dummies Questions & Answers

Redirect time output

Hello All, I am trying to write a script that would capture the output of time command on a Sun machine. I have tried these commands $ time ls > out $ time ls 2> out I just get the ls output in the out file for the first one. Thanks for any help Chuck (2 Replies)
Discussion started by: cbeech
2 Replies

9. UNIX for Dummies Questions & Answers

can you redirect multiple files for input?

I have a program that is reading strings into a vector from a file. Currently I am using this command: a.out < file1 The program runs and prints the contents of the vector to the screen, like its supposed to. The problem is that it needs to read in 3 files to fill the vector. Is there anyway... (4 Replies)
Discussion started by: Matrix_Prime
4 Replies

10. UNIX for Dummies Questions & Answers

Redirect output to multiple files.

Hi, I am new to shell scripting and have a question. I would like to redirect the output of a command to multiple files, each file holding the exact same copy. From what I read from the bash manpage and from some searching it seems it cannot be done within the shell except setting up a loop. Is... (3 Replies)
Discussion started by: cbkihong
3 Replies
Login or Register to Ask a Question