I was wondering if there was a way to use AWK or SED to find certain values that are higher than the argument you gave to the script inside a file. This being
./script.sh CITY VALUE
The value, in this case, is the $2 or second argument which is going to the basis of our search, so if we have a file,
dummy2.txt
Format: Name;ID;Profession;email;rating;number of visits;balance
John Trevolta;12334;dentist;gmail;0;0;431
Isabella;4567;dentist;gmail;0;0;400
and if we input,
./script.sh CITY 400
It should be able to read every column ( the seventh in this case ($7)) from this exact dummy2.txt and output the number of times it finds a value higher than the one we gave it so the desired output would be:
1
But the current Output I'm given is the following:
1 John Trevolta;12334;dentist;gmail;0;0;431
So with this, this is my current code that I have for it:
#!/bin/bash
if [ "$#" -eq 0 ]
then
echo "Please insert arguments"
exit 1
elif [ "$#" -lt 2 ] || [ -z "$1" ]
then
echo "Error 404: No arguments found"
exit 1
else
grep -c "$1" dummy.txt
awk -v x=$2 '$7>x{ i++ }END{ print "Found:" i }' dummy2.txt
fi
I have already added some suggestions found in the comments but unfortunately, it only prints,
Found:
It doesn't start counting the i or even say it's value. I don't know if I need to initialize it or not and if I need to put ''/""/$ on it for it to be read.