I have a file "input.txt" has variables A1, A2, A3, θ, θ1 and θ2 - sample of input.txt is as follows:
$ cat input1.txt
A1=5.2 A2=4.9 A3=6.1 θ=space θ1=2.5 θ2=1.2
A1=3.1 A2=5.1 A3=3.7 θ=triangle θ1=8.1 θ2=3.9
I want to create a script to run over the file input.txt - this file will be passed as a second argument, the first argument would be the value of θ
I created a script as follows:
#! /bin/bash
file=input1.txt
if grep -q $1 "$file";
then
awk -F '[= ]+' '{ print $12 }' <$2
else
echo "Not available"
fi
}
But when I run this script as follows:
./script space input.txt
(first argument is the value of θ and second argument is the file name), the output is all the values in field 12:
$ ./script1 space input1.txt
1.2
3.9
the output should be 1.2 only, I searched and found that I need to create a loop to read the file line by line but I can not get it to work.