2011年6月23日星期四

grep, egrep, fgreb and regular expression

fgrep searches files for one or more pattern arguments. It does not use regular expressions; instead, it does direct string comparison to find matching lines of text in the input.
egrep works in a similar way, but uses extended regular expression matching (as well as the \< and \> metacharacters) as described in the regexp reference page.
Note:
When using the man utility to view the regexp reference page, use the following command to ensure that you get the correct reference page:
man 5 regexp
If you include special characters in patterns typed on the command line, escape them by enclosing them in apostrophes to prevent inadvertent misinterpretation by the shell or command interpreter. To match a character that is special to egrep, put a backslash (\) in front of the character. It is usually simpler to use fgrep when you don't need special pattern matching.
grep is a combination of fgrep and egrep. If you do not specify either -E or -F, (or their long form equivalents, --extended-regexp or --fixed-strings), grep behaves like egrep, but matches basic regular expressions instead of extended ones. You can specify a pattern to search for with either the -e or -f option. If you specify neither option, grep (or egrep or fgrep) takes the first non-option argument as the pattern for which to search. If grep finds a line that matches a pattern, it displays the entire line. If you specify multiple input files, the name of the current file precedes each output line.

http://www.mkssoftware.com/docs/man1/grep.1.asp

http://www.mkssoftware.com/docs/man5/regexp.5.asp

没有评论:

发表评论