Matching Control
-i :Ignore case 忽略大小写
-w:whole words 按照整个单词匹配
-v:Invert the sense of matching, to select non-matching lines 匹配不包含指定关键字的行
Output Line Prefix Control
-n:line number 在行前显示行号
Context Line Control
-A NUM:Print NUM lines of trailing context after matching lines. 显示关键字所在行的后NUM行
-B NUM:Print NUM lines of leading context before matching lines. 显示关键字所在行的前NUM行
-C NUM:Print NUM lines of output context 显示关键字前后NUM行
General Output Control
-c :print a count of matching lines 打印匹配关键在所在行的个数
注
:
此
选
项
只
能
统
计
行
数
\color{#FF3030}{注:此选项只能统计行数}
注:此选项只能统计行数
如果想要统计关键字的个数,则需要使用
-o:only-matching 只显示匹配的关键字
Regular Expression
meta-character | explain |
---|---|
. | The period ‘.’ matches any single character. |
? | The preceding item is optional and will be matched at most once. |
* | The preceding item will be matched zero or more times. |
+ | The preceding item will be matched one or more times. |
{N} | The preceding item is matched exactly N times. |
{N,} | The preceding item is matched N or more times. |
{,M} | The preceding item is matched at most M times. This is a GNU extension. |
{N,M} | The preceding item is matched at least N times, but not more than M times. |
[] | It matches any single character in that list; if the first character of the list is the caret ‘^’, then it matches any character not in the list. |
^,$ | The caret ‘^’ and the dollar sign ‘$’ are meta-characters that respectively match the empty string at the beginning and end of a line. |