Code:
while read line
do
a=$(awk '{ print $2 }' numbers | head -n 1)
...
done < numbers
1) You read the lines from the
numbers file to the
line variable,but then you just ignore it and read the file again by
awk.
head will allways output the first line of what it gets. So, if you just let
awk read from
line, it should work. There's also no need to use
head command, since the
while loop gives you one line at a time:
Code:
while read line
do
a=$(awk '{ print $2 }' <<< "$line")
b=$(awk '{ print $1 }' <<< "$line")
sub=$(echo $a -$b | bc )
echo "a = $a b = $b minus=$sub"
done < numbers
2) There are some nice things in
bash that might help you. Instead of reading the entire line into one variable and then
awking it apart, you can do
Code:
while read a b
...
done < numbers
that will keep putting the first column into
a, and the second one into
b
3) Perhaps the nicest way would be to just use one
awk:
Code:
awk '{printf("a = %f b = %f minus = %f\n", $1, $2, $1 - $2); }' numbers