lundi 22 mai 2017

compare csv file using if statement

I'm reading a "|" delimited file(input.txt) using while loop and comparing columns as below

filename="input.txt"
while IFS='|' read -r f1 f2 f3
do
if [ "$f1" -eq 6002 ] && [ "$f2" == 'test case' ] && [ "$f3" == 'testing' ]
   then
       echo "[$0:$LINENO] not a same output"
       exit 1;
   fi
done < "$filename"

where input.txt

6554|test case|testing

I want if values of all columns is not correct then above code should throw an error otherwise it should pass the result.

Aucun commentaire:

Enregistrer un commentaire