Check for null values in a columns. I have dozen of CSV files in a directory.

Hi Folks,

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 what i have done so far.

for f in *.csv;
do 
  awk -F, '!(NF==6 && $1+0==$1 && $6 == ""){f=1; exit} END{exit f}' "$f" || mv "$f" "$f".bad;
done

So - ?

i am not sure what you mean by ?. in any case never mind.

What ? means is:
Is what you have so far working as you expect it to work? If not, in what way is it failing to work?

  • Are you getting diagnostic messages? (What are they?)
  • Are files being renamed that should not be renamed? (Under what conditions?)
  • Are files not being renamed that should be renamed? (Under what conditions?)

And, if so, where are you stuck in adding code for the remaining checks?

1 Like