I have a file like one below
var 3 2014 string
var1 4 2011 string4
var2 6 1999 string2
var3 1 2016 string6
Then i have this while read loop to compare one of the columns to a number then echo something. However, instead of echoing my desired phrase, it echoes something else.
while read num
do
if [ "$num" = "0" ]; then
echo "Number is equal to zero"
else
echo "number is not equal to 0"
fi
done < home/dir/file.txt | awk '{print $2}'
instead of echoing the above, it echoes the 2nd column of the file.
read numand expect the result to be a single number (which you compare against the string "0"), but you are actually reading an input file with 4 columns so$numwill be a string with 4 columns in it.awk '{if ($2==0){print "equal"}else{print "not"}}' file.txt?while...doneloop. I.e.:isx4