Linux write something across multiple files
4 answers
Use the tee (1) command , which duplicates your standard input to standard output and any files specified on the command line. For example.
printf "Hello \ nthis is a test \ nthank you \ n" | tee test1.txt test2.txt $ OTHER_FILES> / dev / null
Using your example:
cat atest.txt | tee asdasd.txt asgfaya.txt asdjfusfdgh.txt asyeiuyhavujh.txt> / dev / null
+6
source to share
In bash, you can write
#!/bin/bash
$TEXT="hello\nthis is a test\nthank you"
for i in `seq 1 $1`; do echo -e $TEXT >text$i.txt; done
EDIT (in response to changing the question)
If you are unable to programmatically determine the names of the target files, you can use this script it:
#!/bin/bash
ORIGIN=$1;
shift
for i in `seq $#`; do cp "$ORIGIN" "$1"; shift; done
you can use it like this:
script_name origin_file dest_file1 second_dest_file 'third file' ...
If you are wondering why there are double quotes in the cp command, this is for reference with a filename containing spaces
+1
source to share