grep--搜素匹配的字符,正则表达式
grep [options] pattern [FILE...]
grep [options] [-e pattern | -f FILE] [FILE...]
描述
grep searches the named input FILEs for lines containing a match to the given PATTERN. By default, grep prints the matching lines.
Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。
options
-E, --extended-regexp 使用扩展正则表达式Interpret PATTERN as an extended regular expression.
-F, --fixed-strings Interpret PATTERN as a list of fixed strings,separated by newlines, any of which is to be matched.
-G, --basic-regexp Interpret PATTERN as a basic regular expression. This is the default.
-P, --perl-regexp Interpret PATTERN as a Perl regular expression (PCRE, see below). This is highly experimental and grep -P may warn of unimplemented features.
-v, --invert-match 不匹配的行。Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
-w, --word-regexp 打印匹配整个单词的整行。Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.
-x, --line-regexp 打印匹配的整行。Select only those matches that exactly match the whole line. (-x is specified by POSIX.)
-c, --count 打印每个文件匹配的总行数。Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.(-c is specified by POSIX.)
-L, --files-without-match 列出不匹配的文件名。Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.
-l, --files-with-matches 列出匹配的文件名。Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)
-n, --line-number 行前打印行号。Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.)
-i 不区分大小写(只适合单字符)
-h 查询多文件时不显示文件名。
原文:http://www.cnblogs.com/embedded-linux/p/5068209.html