title: How to create a Unix script to segregate data Line by Line?
body: <p>I have some data in a MyFile.CSV file like this:                 </p>
  
  <pre><code>id,name,country                
  100,tom cruise,USA          
  101,Johnny depp,USA           
  102,John,India
  </code></pre>
  
  <p>What will be the shell script to take the above file as input and segregate the data in 2 different files as per the country?</p>
  
  <p>I tried using the FOR loop and then using 2 IFs inside it but I am unable to do so. How to do it using awk?</p>
  
  <pre><code>For LINE in MyFile.CSV               
  Do          
  If grep "USA" $LINE &gt;0 Then  
  $LINE &gt;&gt; Out_USA.csv         
  Else         
  $LINE &gt;&gt; Out_India.csv       
  Done
  </code></pre>