I searched few question and answers on Stack Overflow, but none of them works for my case, and I don't know why my regular expression doesn't work. I'd really appreciate if you can point out my wrong thought.
Test case: text file contains
AllenZhou:9175186661:111th 1111 NY, 11111
XiaoyuZhou:9175186662:2222 222th 22222 NY 22222
Allen:1231231234:abc rd, PA
Here is my function:
checkEntry(){
vaildName=true
while read entry
do
if $( echo $entry | grep --quiet $name)//$name read from keyboard
then
vaildName=false
fi
done < $fileName
}
If I enter Zhou
, my function will return both AllenZhou
, and XiaoyuZhou
. After I did small study, I changed the grep command parameter to
if $( echo $entry | grep --quiet ^$name:$)
It turns out that it never finds anything for AllenZhou
or XiaoyuZhou
– I am confused.
sed -i -n /$name/d $fileName
This is the code I use to delete lines that contains the string pattern. The problem is like with grep, if I type Zhou
or Allen
, the command will delete both lines that contain the keyword. But when I change to
sed -i -n /\<$name\>/d $fileName
it won't delete for AllenZhou
or XiaoyuZhou
or Zhou
... Again I am confused.