How to validate a CSV file?

Hi.
I think some people have already asked this, but the answers/questions seem to be about validating the contents inside a CSV file.

I am simply after a simple variable solution (ie 0 = false, 1 = true) that I can use in my script to say that file so-and-so is actually a CSV file, or in some other format. Is this possible?

I guess the tricky part is defining precisely what a CSV file is. I've seen "CSV" files with commas, but the fields are enclosed in double quotes. I've seen others without double quotes and just commas as the delimiter. I am dealing with the later type.

Thanks in advance.

Assumes that if each line of the file has the same number of comma-delimited fields, then the file is a csv file.

awk 'BEGIN{FS=","}!n{n=NF}n!=NF{failed=1;exit}END{exit !failed}'

Yes. You are correct, but please can you explain this code to me, and how it works? I don't see where I can place the filename that I need to check in this bit of code.
What I am after is some sort of variable statement, to store either YES or NO (1 or 0) to say that the CSV file given in the command is a true CSV file.
Your assumption about the same number of commas per line is correct, and that is good enough for me.
Could I use the above code like this ...

set iscsv = awk 'BEGIN{FS=","}!n{n=NF}n!=NF{failed=1;exit}END{exit !failed}'

??

or?

Perhaps

set iscsv = `awk ' BEGIN{FS=","}!n{n=NF}n!=NF{failed=1;exit}END{print !failed}' file.csv`

Thanks for your help. It's pointed me in the right direction.

Here is what I found and it works fine for me, where $file is a variable that holds the full file name I want to use. In my case I know each file has to have 84 commas per line.

  CSVcnt=`awk 'BEGIN{FS=","}END{print NF}' $file`
  if [[ $CSVcnt != 84 ]] ; then
    echo "ERR03 - FPOS file $file is NOT a CSV file!"
  fi

I tried to place a single line solution using your suggested script, but I gave up trying to get it to work.

Cheers