1831494 Members
3306 Online
110025 Solutions
New Discussion

grep

 
navin
Super Advisor

grep

helo,
i'm using grep to find out a string from a file say "SUNG".but it grep's all entries with "SUNG".Please help to grep the exact string.
Thanks in Advance.
Learning ...
4 REPLIES 4
Dave La Mar
Honored Contributor

Re: grep

Navin -

grep 'SUNG' file_name | grep -v 'SUNGA' | grep -v 'SUNGB'

etc, etc for the other variations of SUNG

Best of luck.

Regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Tom Ward_1
Honored Contributor

Re: grep

grep " SUNG " whatever
or grep -e "^SUNG " -e " SUNG " -e " SUNG$"
Con O'Kelly
Honored Contributor

Re: grep

Hi Navin

Unfortunately grep is not great at matching exact syntax like you want.
For example:
# grep SUNG
This will find all lines with SUNG string, including SUNG, SUNGD, GSUNG ffSUNGfg etc etc.

You need to try and find someway to differentiate the string you are searching for.
Examples:
grep "^SUNG"
All lines that start with SUNG
grep " SUNG "
All lines that have SUNG preceded & followed by a space.
grep -x "SUNG"
All lines that only have SUNG in the line, nothing else.

Hope this might give you some ideas.
If you post the exact string you're trying to match, someone may be able to offer you a solution.

Cheers
Con
navin
Super Advisor

Re: grep

Thanks .It worked.
Learning ...