Operating System - HP-UX
1752723 Members
7615 Online
108789 Solutions
New Discussion юеВ

how to grep a line in a file having '*' as a character

 
vinaykumarmp
New Member

how to grep a line in a file having '*' as a character

how to grep a line in a file having '*' as a character

I am trying in this way. But not working.


FILE="/u/vinaymp/vinay.txt"
crontab -l > tempfile
while read line
do
echo "$line"
grep -E "$line" tempfile

if [ $? -eq 0 ]
then
echo "found"
else
echo "not found"
fi

done < $FILE
4 REPLIES 4
R.K. #
Honored Contributor

Re: how to grep a line in a file having '*' as a character

#grep \* vinay.txt
Don't fix what ain't broke
Dennis Handly
Acclaimed Contributor

Re: how to grep a line in a file having '*' as a character

>how to grep a line in a file having '*' as a character

You can use fgrep and you won't do any RE matching.

What's in vinay.txt?
It seems you want to go out of your with to find EREs with grep -E. If so, your vinay.txt must properly quote your EREs.

As R.K. said, you put "\*" in vinay.txt.
James R. Ferguson
Acclaimed Contributor

Re: how to grep a line in a file having '*' as a character

Hi:

If you are looking to match fixed strings then use 'grep -F'.

In that case there is no need to escape the "*" character.

Regards!

...JRF...
muruganantham raju
Valued Contributor

Re: how to grep a line in a file having '*' as a character

Hi Vinay,
Enclosed * within single quote. It will search the literal character.

grep '*' vinay.txt

HTH
Muru