I have the following AWK statement in a script:
grep -E $city $DATFILE | awk -F "[\t]+" '($3 >= $minbed) && ($4 >= $minsqft) && ($5 <= $maxprice) && ($6 <= $maxweeks)' $DATFILE | sort -nk5 | less
When I run the script, the output is blank. However, if I run the following:
grep -E Toronto listing.dat | awk -F "[\t]+" '($3 >= 2) && ($4 >= 500) && ($5 <= 900000) && ($6 <= 10)' listing.dat | sort -nk4 | less
It outputs as expected.
I have no idea why this is happening, and I have even replaced the awk statement in the script to echo out the variables to make sure they're passing correctly and they are.
Here is the script thus far:
#!/bin/bash
DATFILE=listing.dat
if [ -f ${DATFILE} ];
then
echo -n "Are you looking into anywhere in the GTA, or a specific city?: "
read uinput
if [ $uinput == "anywhere" ];
then
echo "You have chosen anywhere"
elif [ $uinput == "specific" ];
then
echo -n "Which city?: "
read city
echo -n "Minimum Number of Bedrooms: "
read minbed
echo -n "Minimum Square Footage (500, 600, etc): "
read minsqft
echo -n "Maximum Price: "
read maxprice
echo -n "Maximum Weeks On Market: "
read maxweeks
echo -n "Sort by (price, sqrft, weeks): "
read sortby
if [ $sortby == "price" ];
then
echo -n "Sort by (asc, desc): "
read ascdesc
if [ $ascdesc == "asc" ];
then
grep -E $city $DATFILE | awk -F "[\t]+" '($3 >= $minbed) && ($4 >= $minsqft) && ($5 <= $maxprice) && ($6 <= $maxweeks)' $DATFILE | sort -nk5 | less
elif [ $ascdesc == "desc" ];
then
grep -E $city $DATFILE | awk -F "[\t]+" '($3 >= $minbed) && ($4 >= $minsqft) && ($5 <= $maxprice) && ($6 <= $maxweeks)' $DATFILE | sort -rnk5 | less
fi
fi
fi
else
echo "${DATFILE} Not found!"
fi
Can you please help?
Thanks