user3389597
user3389597

Reputation: 471

Shell command to loop over names of output file

I have a C code and I use it to extract file and write in to separate files such as exax0.txt, ..., exax202.txt. To do that I use

for i in $(seq 0 202); 
do echo $i | ./f.out exa-NO-hyp.bin exax${i}.txt <<< "${i}"
done

Instead, I would like to have my output files named as exax495.txt, exax535.txt, ..., exax8545.txt. To do so, I tried something like:

for i in $(seq 0 202); 
do echo $i | ./f.out exa-NO-hyp.bin exax${(i*40+495)}.txt <<< "${i}"  
done

But it says, -bash: exax${i*40}.txt: bad substitution

Can anybody please help me with this?

Upvotes: 2

Views: 44

Answers (1)

You can use $((...)) to perform arithmetic.

I.e. a simple use would be:

for i in {1..10}; do touch file$(($i+5)).txt ; done

Or in your case:

for i in $(seq 0 202); do echo $i | ./f.out exa-NO-hyp.bin exax$(($i*40+495)).txt <<< "${i}"; done

See also:

Upvotes: 2

Related Questions