Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch processing? 2

Status
Not open for further replies.

LovecraftHP

Programmer
Dec 3, 2002
15
CN
Hi guys! I'm new to Linux so excuse me if the answer to this should turn out to be too obvious. I am working with numbered files eg train1.txt, train2.txt etc. Is there a way to execute a command on these files and make the number variable? What I mean is something like:

Code:
for (x=1;x<=10;x++) do program trainx.txt

I have experimented a bit with the Linux for do command but haven't had any success so far. If anyone could please help me out? Thanks.
 
Sure

for i in `seq 1 20`
do
eval train$i
done

or

for i in 1 2 3 4
do
eval train$i
done

or

x=2
while [ $x -lt 20 ]
do
eval train$x
x=$((x + 2))
done





Tony Lawrence
Linux/Unix/Mac OS X Resources
 
for ((x=1;x<=10;x++)); do program trainx.txt; done


--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Thanks guys! Works perfectly now and saves me a lot of time. Thanks!
 
My bash is a bit rusty, but I seem to remember you can do something like
Code:
for x in $(ls train*.txt); do program $x; done;
 
Of course, if 'program' accepts multiple files on the command line (as many *nix programs do), then you only need to
Code:
program train*.txt
to have the shell expand the parameter list to include all the matching files...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top