Sep 5, 2003 #1 gxh1000 Programmer Aug 4, 1999 10 US I need to validate that each record contains exactly 5 comma separated fields in my file. ex. a,b,c,d,e If any record doesn't match the format, then fail. Thanks for your help.
I need to validate that each record contains exactly 5 comma separated fields in my file. ex. a,b,c,d,e If any record doesn't match the format, then fail. Thanks for your help.
Sep 5, 2003 #2 vgersh99 Programmer Jul 27, 2000 2,146 US nawk -f val.awk data.txt if [ $? -ne 0 ] ; then echo "failed" fi #--------------- val.awk BEGIN { FS="," st="0" } NF != 5 { st=1; exit } END { exit st; } vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+ Upvote 0 Downvote
nawk -f val.awk data.txt if [ $? -ne 0 ] ; then echo "failed" fi #--------------- val.awk BEGIN { FS="," st="0" } NF != 5 { st=1; exit } END { exit st; } vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+
Sep 5, 2003 #3 PHV MIS Nov 8, 2002 53,708 FR Try something like this: Code: awk -F, 'NF!=5' /path/to/yourfile >/tmp/check$$ [ -s /tmp/check$$ ] && { echo "PROBLEM with fields:"; cat /tmp/check$$ exit 1 } Hope This Help PH. Upvote 0 Downvote
Try something like this: Code: awk -F, 'NF!=5' /path/to/yourfile >/tmp/check$$ [ -s /tmp/check$$ ] && { echo "PROBLEM with fields:"; cat /tmp/check$$ exit 1 } Hope This Help PH.
Sep 5, 2003 #4 Salem Programmer Apr 29, 2003 2,455 GB This should get you started... Code: BEGIN { FS="," } NF != 5 { # fail code goes here } Upvote 0 Downvote