First off, I'm not allowed awk, sed or perl.
For my assignment I was given a file of employee list:
Marketing Ranjit Singh FULLEagles Dean Johnson
Marketing Ken Whillans FULLEagles Karen Thompson
Sales Peter RobertsonPARTGolden TigersRich Gardener
President Sandeep Jain CONTWimps Ken Whillans
Operations John Thompson PARTHawks Cher
Operations Cher CONTVegans Karen Patel
Sales John Jacobs FULLHawks Davinder Singh
Finance Dean Johnson FULLVegans Sandeep Jain
EngineeringKaren Thompson PARTVegans John Thompson
IT Rich Gardener FULLGolden TigersPeter Robertson
IT Karen Patel FULLWimps Ranjit Singh
Long story short, the user is prompted to give a name or portion of a name and that word is searched for ONLY in the second 'column'. If it is found there then the user is then asked whether they want the person's team-name (third column, word next to "PART" or "FULL" etc.) or the person's partner (last column).
The end result is then only to show the full name alongside the team name or partner.
I can't figure out the last step... Cutting only the lines with the matches to the original search and displaying only the needed 'columns'.
while :
do
echo Enter the name of the player you want to search for:
read name
if (cut -c12-26 emplist | grep -n ${name} > namefile)
then
while :
do
echo 'See partner (P/p) or team name (T/t)?'
read answer
if [ ${answer} = "T" -o ${answer} = "t" ]
then
**#Steps for showing only the full name and the team name**
break
elif [ ${answer} = "P" -o ${answer} = "p" ]
then
**#Steps for showing only the full name and the partner name**
break
else
echo Please enter only T or M.
fi
done
elif [ ${name} = "ZZZ" ]
then
break
else
echo Name not found.
fi
done
EngineeringandKarenand the three other cases where your columns are fused right? Are the columns separated by tabs? How can you know whether there will be a full name (John Doe) or not (Cher) otherwise?[ ${name} = "ZZZ" ]should be[ "$name" = ZZZ ]. The{}aroundnameand""aroundzzzare not necessary, the quotes around$name(or${name}) are. quotes don't serve the same purpose in shells as they do in other languages. Consider usingcaseinstead ofif/elif/...here.