I am newbie to BASH scripting and was wondering if you could point me in the right direction. I have CSV file with the following field names separated by ","
no,name,score,city
I am trying to develop a script that will take 1 argument (in numeric format), search "score"column in csv file and extract entries greater than the given argument.
I am not allowed to use awk to achieve this, following is my draft code. I have tried different logic and approaches with cut and grep but don't get the desired results such as below. Is there any switch that I can use with grep to specify the field and apply condition ?
cut -f1,2,3,4 -d, sample.csv | grep 108
Additionally - I have prepared below script but having issues with the syntax and was wondering if anyone could help me or give me a hint. Thank you
EDITED
#!/bin/bash
file="sample.csv"
arg="$1"
while IFS=',' read -r f1 f2 f3 f4
do
if [ "$f3" -gt "$arg" ]
then
echo "$f1,$f2,$f3,$f4"
else
echo "No score greater than "$arg""
fi
done < $file
test(1)after you fix the typo.IFS=',' read f1 f2 f3 f4only works if you can ensure, that no member contains a newline and/or a comma! A counterexample for a city with comma is the german cityWetter, Ruhr.bashalways call other tools/programs, I can provide a bash/php solution, where the php call looks likephp -r 'some commands;'.