温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

grep常见选项及命令

发布时间:2020-06-11 11:44:03 来源:网络 阅读:1073 作者:小镇青苔 栏目:网络安全


-E 按Extended规范进行匹配


--color 标记匹配颜色


-i 忽略大小写匹配

[fbl@www test6_26]$ echo "hello" | grep -i --color 'HELLO'
hello


-q 安静匹配 即不输出内容

[fbl@www test6_26]$ echo "hello" | grep -q --color 'hello'
[fbl@www test6_26]$ echo $?
0

-o 只输出匹配到的部分

[fbl@www test6_26]$ echo "hello" | grep -E -o --color 'hell*'
hell


-w 只显示全字符合的lie

[fbl@www test6_26]$ cat file1
hello
helloo
hell
[fbl@www test6_26]$ cat file1 | grep -E --color 'hell'
hello
helloo
hell
[fbl@www test6_26]$ cat file1 | grep -wE --color 'hell'
hell


[fbl@www test6_26]$ cat file

apple

bahyude

nue

111123

88888

hello

change

brance

6666

[fbl@www test6_26]$ cat file | grep -E --color '^[a-z]{1,}[a-z]$'
apple
bahyude
nue
hello
change
brance

-c 输出匹配到的列数

[fbl@www test6_26]$ cat file | grep -cE --color '^[a-z]{1,}[a-z]$'
6

-n 显示匹配到的列及列号

[fbl@www test6_26]$ cat file | grep -nE --color '^[a-z]{1,}[a-z]$'
1:apple
2:bahyude
3:nue
6:hello
7:change
8:brance

-v 显示不匹配的列

[fbl@www test6_26]$ cat file | grep -vE --color '^[a-z]{1,}[a-z]$'
111123
88888
6666

-a 偏移匹配

[fbl@www test6_26]$ cat file | grep -a2 --color 'hello'
111123
88888
hello
change
brance


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI