PDA

View Full Version : how to make grep ignore special characters



mkrahmeh
July 7th, 2008, 11:24 PM
usually i use grep to search long man pages for certain options rather than going through the whole manual..however when i need to view the part related to certain option, grep interprets that option as its own which causes unexpected behaviour or displaying available options for grep..for instance i need to check what -r exactly does in userdel as in

man userdel | grep -r
now grep modifies its behaviour accordingly, but i need it to search for -r in the man page instead..


man grep | grep exact
ddnt really help :)
any suggestions ??

sisco311
July 7th, 2008, 11:29 PM
man userdel | grep -- -r-- = end options
or

man userdel | grep -A 10 -- -r



-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines.
Places a line containing a group separator (--) between
contiguous groups of matches. With the -o or --only-matching
option, this has no effect and a warning is given.

mkrahmeh
July 8th, 2008, 11:32 AM
thx, this solves the problem.
now how can i search for a sequence of words, like

man grep | grep "end options"
preferably case insensitive search

sisco311
July 8th, 2008, 11:39 AM
man grep | grep -i -A 3 -- "--IgnorE-CasE"

AboSamoor
July 8th, 2008, 09:54 PM
I hope this will work:

man userdel | grep '\-r'

mkrahmeh
July 10th, 2008, 08:07 PM
thx guys..u rock
:guitar: