title: Shell script to validate a csv file column by column
body: <p>I was wondering how I would go about writing this in shell? I want to validate a field in a csv file coulmn by coulmn. For example  only want to validate if coulmn number one is number</p>
  
  <pre><code>Number,Letter
  
  1,u
  2,h
  3,d
  4,j
  </code></pre>
  
  <p>above</p>
  
  <pre><code>Loop - for all files (loop1)
  
   loop  from rows(2-n) (loop2) #skipping first row since its a header
  
       validate column 1
  
       validate column 2
  
       ...
  
       end loop2
             if( file pass validation)
                 copy to goodFile directory
             else(
                  send to badFile directory
  
  
   end loop1
  </code></pre>
  
  <p>What I have here below is a row by row validation, what modification would i need to make it like the above psuedo code i have above. I am terrible at unix just started learning about awk.</p>
  
  <pre><code>#!/bin/sh
  
  for file in /source/*.csv
  
   do
     awk -F"," '{                       # awk -F", " {'print$2'} to get the     fields.
  $date_regex = '~(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d~';
  
  if (length($1) == "")  
      break
  if (length($2) == "") &amp;&amp; (length($2) &gt; 30)
      break
  if (length($3) == "") &amp;&amp; ($3 !~ /$date_regex/)
      break
  if (length($4) == "") &amp;&amp; (($4 != "S") || ($4 != "E")   
      break
  if (length($5) == "") &amp;&amp; ((length($5) &lt; 9 || (length($5) &gt; 11)))
      break
  
  
  
  }' file
  
     #whatever you need with "$file"
  </code></pre>
  
  <p>done</p>