Skip to content

Instantly share code, notes, and snippets.

@vapniks
Created April 11, 2018 03:51
Show Gist options
  • Save vapniks/499b908ace3345ed0f24fe1ca0e79da9 to your computer and use it in GitHub Desktop.
Save vapniks/499b908ace3345ed0f24fe1ca0e79da9 to your computer and use it in GitHub Desktop.
A simple awk script to check a .csv file
#!/usr/bin/awk -f
BEGIN {FS=","}
$1 !~ /^[0-9]+$/ {print "Line "NR": Field 1 invalid"}
$2 !~ /^"?[a-zA-Z][^,]+"?$/ {print "Line "NR": Field 2 invalid"}
$3 !~ /^[0-9.]+$/ {print "Line "NR": Field 3 invalid"}
$4 !~ /[0-9]+/ {print "Line "NR": Field 4 invalid"}
$5 !~ /[0-9](\.[0-9])? - [0-9](\.[0-9])?/ {print "Line "NR": Field 5 invalid"}
/^$/ { print "Line "NR" is empty" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment