grep常见选项及命令-创新互联

-E 按Extended规范进行匹配

专注于为中小企业提供成都做网站、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业凤泉免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

--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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:grep常见选项及命令-创新互联
标题网址:http://lszwz.com/article/dippsi.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款