Need some help on scripting for validating the files before loading

Hi,

I need to perform some validation steps on the files before I start loading them.

  1. I need to check for the availabilty of the file in expected path with expected name.
  2. I need to check If the file format is correct.
    a. confirm if correct delimiter is used.
    b. confirm name, number and order of the columns.

Filename: SDsheet.csv
Delimiter used: ";"
10 columns are used with the name and order A,C,D,F,K,M,O,R,S,U.

Can anyone please help me how to validate these steps before I process to load the file.

Thanks in advance..

  1. Assuming the file extension is csv
if [ "${filename##*.}" != "csv" ]; then
  echo "$filename extension is not .csv"
  exit 1
fi
if [ !-r $filename ]; then
  echo "$filename does not exist or readable"
  exit 1
fi

Delimiter

awk -F";" 'NF!=10{exit(1)}' $filename
if [ $? -eq 1 ]; then
  echo "$filename does not contain 10 records in each row"
  exit 1

As for the "confirm name, number and order of the columns.", pls elaborate with examples.