2020-10-30

I want to search a file to find a user name and print that person's name [closed]

I want to search a file by username to find a person and then print out their name. For example, FileName contains a list in the format First,Middle,Last,username: John,Tyler,Smith,johnts Rob,Danial,Wright,robdw Chris,Eric,Graham,chriseg

When I run ./findName.sh johnts it prints out: John,Tyler,Smith,johnts What do I need to do so that it would just print the name John Tyler Smith without the username johnts?

#1 /bin/bash
# findName.sh
searchFile="FileName"
if[[ $1 = "" ]]; then
echo "Command line arguments are not equal to 1"
exit 2
fi
grep -i $1 ${searchFile}
grep -i $1 ${searchFile}
if [[ $? = "1" ]]; then
echo "Sorry that person is not on the list"
fi


from Recent Questions - Stack Overflow https://ift.tt/2TyzhNe
https://ift.tt/eA8V8J

No comments:

Post a Comment