I have 10 files with the name of
data_00
data_01
data_02
...
data_09
The first 8 lines of the data files look like the following:
Stamp_number
10
Item_number
9000
Position
5.1008068168967009e+00 5.4899193183110690e+01
5.1008068168967009e+00 5.4899193183110690e+01
5.1008068168967009e+00 5.4899193183110690e+01
All 10 files have the same format but different values for all numbers.
I wish to assign a bash variable using awk for the values of the 6th, 7th, and 8th lines of the 1st and 2nd columns of 10 files and get the difference between them.
for i in {00..09}; do
a=$(awk 'NR==6 {print $1}' data_$i)
b=$(awk 'NR==6 {print $2}' data_$i)
c=$(awk 'NR==7 {print $1}' data_$i)
d=$(awk 'NR==7 {print $2}' data_$i)
e=$(awk 'NR==8 {print $1}' data_$i)
f=$(awk 'NR==8 {print $2}' data_$i)
val_ab=`bc -l <<< "$a-$b"`
val_cd=`bc -l <<< "$c-$d"`
val_ef=`bc -l <<< "$e-$f"`
echo $val_ab
echo $val_cd
echo $val_ef
done
But this prints out the following syntax error 10 times:
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
0.000000
0.000000
0.000000
I tried data_"$i", data_[$i], data_${i} but all fails. How can I use the for-loop index i (or any other bash variable) inside the awk command substitution to assign a bash variable?