Reputation: 1
Hi I have a file that sorts some code and reformats it. I have over 200 files to apply this to with incremental names run001, run002 etc. Is there a quick way to write a shell script to execute this file over all the files? The executable creates a new file called run001an etc so just running over all files containing run doesnt work, how do i increment the file number?
Cheers
Upvotes: 0
Views: 41
Reputation: 75458
To be more specific with run###
files you can have
for file in dir/run[0-9][0-9][0-9]; do
do_something "$file"
done
dir
could simply be just . or other directories. If they have spaces, quote them around ""
but only the directory parts.
In bash, you can make use of extended patterns to generate all number matches not just 3 digits:
shopt -s extglob
for file in dir/run+([0-9]); do
do_something "$file"
done
Upvotes: 0
Reputation:
how about:
for i in ./run*; do
process_the_file $i
done
which is valid Bash/Ksh
Upvotes: 1