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?
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
$ echo "hello" > *.txt -bash: !": event not foundCode:
also cat ~/otherdir/test.txt > *.txt -bash: *.txt: ambiguous redirect
Ok i solved it
#! /bin/bash for file in *.txt do echo "Text that needs to be written" > $file done
Last edited by SQuIDers; 11-12-2010 at 01: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:
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!