shell 之 grep 持续更新
程序员文章站
2022-03-11 11:49:16
...
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
刚才从同事那里得到了一张神图,是vi的,顺便贴在这吧
推荐阅读
-
Shell正则表达式之grep、sed、awk实操笔记
-
Javascript之常见算法整理(持续更新)-柠檬味的前端-SegmentFault思否
-
shell脚本之正则表达式、grep、sed、awk
-
Python之Pandas and Numpy 吐血整理(持续更新!!!)
-
Linux Shell 编程基础(持续更新)
-
shell 脚本汇总 (持续更新中)
-
【学习笔记】python之BeautifulSoup(持续更新)
-
Shell正则表达式之grep、sed、awk实操笔记
-
MySQL之使用过程中报错及处理记录(持续更新)
-
体悟与总结之虫师作品《Web接口开发与自动化测试...Python..》问题处理(持续更新。。。)