I was wondering if there was a way to use AWK or SED to find certain values in a certain file that are higher than the argument you gave to the script. This being
./script.sh CITY VALUE
The value, in this case, is the $2 or second argument which is going to the minimum value 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
Maria;888;General Doctor;hotmail;4;2;700
Joseph;127;Intern;outlook;0;0;450
and if we input,
./script.sh Lisbon 400
(Ignore the Lisbon/CITY part as it doesn't pose a problem and it reads it from another file)
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:
Found: 3
But the current Output I'm given is the following if I use the following expression:
awk -F';' '$7>=x' x="$2" medicos.txt | sort | uniq -c
1 John Travolta;12334;dentist;Gmail;0;0;431
1 Maria;888;General Doctor;hotmail;4;2;700
1 Joseph;127;Intern;outlook;0;0;450
OR
This is the output when with the current expression:
awk -v x=$2 '$7>x{ i++ }END{ print "Found:" i }' dummy2.txt
Found:
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
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.
Previous post which was a mess and everything was all over the place:
Counting the number of occurences or higher value in a file
Updated it but it remains closed.