Results 1 to 3 of 3
Hello everyone. I feel kind of embarrassed posting here, but this is technically a scripting sub-forum.
Here is the problem
I have a folder with various files which include .txt ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-12-2010 #1
[SOLVED] redirect to multiple files?
Hello everyone. I feel kind of embarrassed posting here, but this is technically a scripting sub-forum.
Here is the problem
I have a folder with various files which include .txt files as well
How can i redirect same content to each of the .txt files in the folder?
I have tried
Code:$ echo "hello" > *.txt -bash: !": event not found
Can anyone help me with this?Code:also cat ~/otherdir/test.txt > *.txt -bash: *.txt: ambiguous redirect
Ok i solved it
Code:#! /bin/bash for file in *.txt do echo "Text that needs to be written" > $file done
Last edited by SQuIDers; 11-12-2010 at 12:59 PM.
- 11-13-2010 #2
This is one way to do it. But it won't always work. For instance, what if you were running a real command that actually did something (like add a user). You don't want to run the command multiple times, but you want the output in multiple files.
The solution is to use the "tee" program. "tee" takes all of its input and writes it to multiple files, as well as to standard output:
Code:echo 'Hello, world!' | tee file1 file2 file3
- 11-13-2010 #3
This is actually the first time i heard of command tee.
Thank you very much!



