Write Shell script to split the below file into two files
male_nominee.txt
andfemale_nominee.txt
based on gender. If filemale_nominee.txt
orfemale_nominee.txt
already exists, then append the content.Display the contents of
female_nominee.txt
andmale_nominee.txt
names.txt
23|Arjun|Male
24|Akshara|Female
17|Aman|Male
19|Simran|Female
My code:
while IFS= read -r line;
do
if i=$(grep "Male" names.txt)
then
echo "$line" >> male_nominee.txt
fi
if j=$(grep "Female" names.txt)
then
echo "$line" >> female_nominee.txt
fi
done < "names.txt"
ls
cat male_nominee.txt
cat female_nominee.txt
In my output, I have the contents of names.txt
in both my files. Can someone help me with this problem?