linux - How to make a loop with multiple columns in shell? -


i have file 3 columns (id number, x, y)

ifile.txt 1      32.2    21.4 4      33.2    43.5 5      21.3    45.6 12     22.3    32.5 32     21.5    56.3 43     33.4    23.4 44     23.3    22.3 55     22.5    32.4 

i make loop on column 2 , 3 read

for x=32.2 , y=21.4; execute fortran program x=33.2 , y=43.5; execute same program , on 

though following script working, need in efficient way.

s1=1   #serial number s2=$(wc -l < ifile.txt)   #total number loop while [ $s1 -le $s2 ] x=$(awk 'nr=='$s1' {print $2}' ifile.txt) y=$(awk 'nr=='$s1' {print $3}' ifile.txt) cat << eof > myprog.f ... take value of x , y ... eof ifort myprog.f ./a.out (( s1++ )) done 

kindly note: myprog.f written within cat program. example,

cat << eof > myprog.f .... .... take value of x , y .... .... eof 

simple way read file in bash

while read -r _ x y;     echo "x $x, y $y"     # fortran code execution done < ifile.txt x 32.2, y 21.4 x 33.2, y 43.5 x 21.3, y 45.6 x 22.3, y 32.5 x 21.5, y 56.3 x 33.4, y 23.4 x 23.3, y 22.3 x 22.5, y 32.4 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -