I have a question about for loop in Bash I want to run awk command for specific range increasing by 34 but I don't know how to specify two variable in a for loop. I know how to do it for one variable but it is not working for two. this is my code for one variable:
#!/bin/bash
for a in {1..3400..34}
do
printf "awk 'NR>=$a&&NR<=$b { if (/^[0-9]/) sum++} END {print "row\t", sum }' file "
done
but I want to specify both variables ($a,$b), something like this which is not working! :
for a in {1..3400..34} , for b in {35..3400..34}
do
printf "awk 'NR>=$a&&NR<=$b { if (/^[0-9]/) sum++} END {print "row\t", sum }' hydr_dE.txt && "
done
Thanks,
Using C-style for loop:
for ((a=1,b=35;a<=3400,b<=3400;a+=34,b+=34)); do
echo ": $a :: $b :"
done
(will have the same output as devnull's answer, but in pure Bash).
Of course, in this simple case, it's enough to just do:
for ((a=1;b=a+34,b<=3400;a+=34)); do
echo ": $a :: $b :"
done
I'm sure you'll be able to figure out how to adapt this to what you exactly want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With