title: Loop through rows and multiple columns in bash
body: <p>I'm trying to do a loop on a file which has a number of rows with multiple columns (fields) with conditions. </p>
  
  <p>Here is what a sample file (<code>file.txt</code>) looks like:</p>
  
  <pre><code>aaa  bbb  ccc
  ddd  kkk
  fff  ggg  hhh lll
  ooo
  sss
  </code></pre>
  
  <p>...etc...</p>
  
  <p>I want to write a bash script that loops over first row of the first field  and if the name exists then continues to the second row. If the name of the first row of the first field does not exist test then test the second field (in this case test the name "bbb") and so on until the fourth. I have a variable field numbers with a maximum of four(4) fields and a minimum of one field (column) for a given row.</p>
  
  <pre><code>for i in cat file.txt; do 
      echo $i
      if [ -e $i ]; then
          echo "name exists"
      else
          echo "name does not exist"
      fi
  done 
  </code></pre>
  
  <p>Obviously the above script tests both rows and columns. But I wanted also to loop through to the second, third and fourth fields if the first field does not exist and if the second field does not exist test the third field and until the fourth.</p>