I'm trying to write a simple file sanity check script. I have a directory with dozen CSV files containing id,edname,firstname,lastname,suffix,email.
I like to write a awk script to check if first field contain a number and is not empty. and fields number 3,4 & 6 are not empty and that the file contains 6 fields no more no less than 6, if all of this conditions are true nothing happens but if any of these conditions failed, re-name the file to .bad. here is wha i have but is not picking up missing values in columns 4,6.
for f in *.csv; do
awk -F, '!(NF==6 && $1+0==$1 && $3$4$6!=""){f=1; exit} END{exit f}' "$f" || mv "$f" "$f".bad;
done
$3$4$6!=""
will return true if at least one of the fields is non-empty. Is that what you really want?