shell 之 grep 持续更新

grep -E 'stra|strb'	// 查找包含stra或strb的行
grep ^str		// 查找以str开头的行
grep -i str		// 忽略大小写
grep -rl str /root	// 在/root下查找包含str的文件,并只列出文件名 -r表示递归目录匹配
grep -n str		// 显示行号
grep --color str	// 染成红色或加重
grep -e			// 将两个表达式连在一起,比如:grep -e ^str1 -e str2$ ????
grep -B12 str        // 显示str所在行及其前12行
grep -A23 str        // 显示str所在行及其后23行
grep -C34 str        // 显示str所在行及其前后34行


附:

[abc]	A single character: a, b or c
[^abc]	Any single character but a, b, or c
[a-z]	Any single character in the range a-z
[a-zA-Z]	Any single character in the range a-z or A-Z
^	Start of line
$	End of line
\A	Start of string
\z	End of string
.	Any single character
\s	Any whitespace character
\S	Any non-whitespace character
\d	Any digit
\D	Any non-digit
\w	Any word character (letter, number, underscore)
\W	Any non-word character
\b	Any word boundary character
(...)	Capture everything enclosed
(a|b)	a or b
a?	Zero or one of a
a*	Zero or more of a
a+	One or more of a
a{3}	Exactly 3 of a
a{3,}	3 or more of a
a{3,6}	Between 3 and 6 of a
options: i case insensitive m make dot match newlines x ignore whitespace in regex o perform #{...} substitutions only once



在线测试:http://www.rubular.com/

刚才从同事那里得到了一张神图,是vi的,顺便贴在这吧

猜你喜欢

转载自fandayrockworld.iteye.com/blog/1262539