I have a script which function like this for one file../script 0001g.log > outputfor two or more files, like this./script 0001g.log 0002g.log 0003g.log > outputThe script take one special number from each input file and put it in one output file.My question is I have 1000 input files, how can I do a loop to execute my script.
How to do a loop to execute many files
shell script;command line
You have a few possible solutions:Simply$ ./script *g.log >output... and hope that *g.log doesn't expand to something that makes the command line too long. This is not very robust.If your script doesn't depend on the number of files given to it, i.e., if output can just be appended to output for each input file, then this is another solution:$ find ./ -type f -name *g.log | xargs ./script >outputA third solution would be to move the loop into the script itself:for f in *g.log; do  # old code using $f as file namedoneThis does not have the problem with command line length restriction since it's in a script.The invocation of the script would now be$ ./script >output