I need to make files called from File1, File2, ... to File99.
I tried the following unsuccessfully
cat test > {File1 .. File99}
The command without the word File did not work.
I need to make files called from File1, File2, ... to File99.
I tried the following unsuccessfully
cat test > {File1 .. File99}
The command without the word File did not work.
This will depend on the shell you are using. I assume you are using Bash.
According to http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion, Bash will expand digits and single characters. So your brace expression should be:
File{1..99}
But I don't think the redirection operator ">" can output to multiple files. You might need to use a loop:
for output in File{1..99}
do
cat test > $output
done
Or as a one-liner:
for output in File{1..99}; do cat test > $output; done
If you prefer a non looping version then you can use tee
cat test | tee File{1..99} > /dev/null
With zsh (with its *mult_ios*) you can :)
% zsh -c 'print test > file{1..3}'
% head file*
==> file1 <==
test
==> file2 <==
test
==> file3 <==
test
If you want the files to sort properly (file01, file02 ... file10, etc.), do this:
for i in {0..10}; do i="0"$i; touch file${i: -2}; done
Which is the same as:
for i in {0..10}
do
i="0"$i
touch file${i: -2} # or cat file > file${i: -2}
done
There must be be a space between the colon and the dash in the substring expansion clause. You can start the ranges above with 1 if you want to start with "file01".
Or, a much more succinct way to have leading zeros:
touch file{0..9}{0..9}
and to use phyrex1an's technique with this one:
cat test | tee File{0..9}{0..9} > /dev/null
This does make one extra file "file00". You can also do "{2..3}{0..9}" for "file20" through "file39", but changing the ones digit (the second range) would cause parts of the sequence to be skipped.