title: Split text file into two based on gender in a line
body: <p>I have to write a Shell script to split the <code>names.txt</code> file into two files <code>male_nominee.txt</code> and <code>female_nominee.txt</code> based on gender.</p>
  <p>If file <code>male_nominee.txt</code> or <code>female_nominee.txt</code> already exists, then append the content otherwise we have to make the files.
  <code>names.txt</code> has text like this:</p>
  <pre><code>23|Arjun|Male
  24|Akshara|Female
  17|Aman|Male
  19|Simran|Female
  </code></pre>
  <p>I wrote the following script but something is not right:</p>
  <pre><code>#!/bin/bash -x
  if [ -f male_nominee.txt ] 
  then
       grep -n &quot;Male&quot; names.txt &gt; male_nominee.txt
  else
       mkdir -p male_nominee.txt
       grep -n &quot;Male&quot; names.txt &gt; male_nominee.txt
  fi
  if [ -f female_nominee.txt ]
  then 
      grep -n &quot;Female&quot; names.txt &gt; female_nominee.txt
  else
      mkdir -p female_nominee.txt
      grep -n &quot;Female&quot; names.txt &gt; female_nominee.txt
  fi
  </code></pre>