Reputation: 471
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
Reputation: 50858
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
Upvotes: 2