I have a scenario where i have following below data in Student file
My Student.txt
data input, need to follow a pattern, on each line need to contains three infos separated by /
as follows:
NAME/SURNAME/COUNTRY
So, below I have an example of file that is fine:
RAM/ABC/INDIA
RAJ/XYZ/DELHI
VIRAJ/FDS/GUJRAT
WHAT IS EXPECTED:
Each and every record in file should match with that syntax: NAME/SURNAME/COUNTRY
.
If anyone fails then, the overall status should be displayed as failed, with the message syntax does not match
, otherwise, mark as success.
WHAT'S HAPPENING:
If I pass data to above code like below:
RAM/ABC/INDIA
RAJ/XYZ/DELHI
VIRAJ/FDS/
When I execute the my code, I don't get any error saying failed:
syntax does not match
it simply check upto below two records
RAM/ABC/INDIA
RAJ/XYZ/DELHI
The last record in file, that is VIRAJ/FDS/
does not check and not thrown error failed: syntax does not match
My code:
for i in `cat /demo/Student.txt`
do
check=`echo $i | cut -d '/'-f3`
if [[ -z $check ]];
then
echo failed syntax does not match NAME/SURNAME/COUNTRY
exit 1
fi
done