HI
Input file.txt
ABCDE1 JFHFJFJF3 10
ABCDE2 JFHFJFJF5 20
ABCDE3 JFHFJFJF5 30
ABCDE4 JFHFJFJF6 -
ABCDE5 JFHFJFJF6 20
ABCDE6 JFHFJFJF6 90
ABCDE7 JFHFJFJF6 9
ABCDE8 JFHFJFJF6
I want to check third column if data missing or wrong data the echo massage and out from script.
all three column must have data.
Third column have value between 0 or 10 to 180 but not (1,2,3,4,5,6,7,8,9)
Third column not be blank
Output;
Script have error in Below Line
ABCDE4 JFHFJFJF6 -
ABCDE7 JFHFJFJF6 9
ABCDE8 JFHFJFJF6
Please verify your input and run the script again
awk ' BEGIN{print "Script have error in Below Line" ; bad=0}
{ ok=0
ok=(NF==3)?1:0
if(ok) {ok=($(NF)==0 || ($(NF)<=100 && $(NF)>=10)?1:0}
if(!ok} {print $0; bad++}
next;
}
END
{print (bad==0) ? "no errors found" :
"Please verify your input and run the script again " } ' inputfile
Try that
Yoda
November 19, 2012, 9:41pm
3
awk ' { if(!(($3 >= 10 && $3 <= 180) || ($3 == 0))) print; } ' input_file
awk 'NF!=3 || $NF ~ /^([1-9]|-)$/' file
awk ' { if(!(($3 >= 10 && $3 <= 180) || ($3 == 0))) print; } ' input_file
awk 'NF!=3 || $NF ~ /^([1-9]|-)$/' file
Both script are good but i want to stop the script and give error massage ...
you can try this..
nawk ' ( ($1!~/[A-Za-z0-9]/ || $2!~/[A-Za-z0-9]/ || $3!~/[A-Za-z0-9]/ ) || ( $3==0 || ( ($3<10 && $3>180) || ($3>=1 && $3<=9) ))) { print $0 }' InputFile.txt
ABCDE4 JFHFJFJF6 -
ABCDE7 JFHFJFJF6 9
ABCDE8 JFHFJFJF6
thanks guys but how can i give error massage
#!/bin/bash
#blah
#blah
#blah
if awk 'NF!=3 || $NF ~ /^([1-9]|-)$/{if(!bad){print "Script have error in Below Line\n";bad=1};print}END{exit(bad?0:1)}' file
then
echo -e "\nPlease verify your input and run the script again"
exit 1
fi
#more blah
#more blah
#more blah
1 Like
thanks elixir_sinari
it's perfect .....How can i add
awk ' { if(!(($3 >= 10 && $3 <= 180)
in your code