grep 命令使用(2)

grep 参数-w 精准匹配查找的内容并输出所在行

[root@localhost scripts]#cat sedtext
qwerrrr
wewq
wew1
erw
wew
[root@localhost scripts]#grep "wew" sedtext
wewq
wew1
wew

[root@localhost scripts]#grep  -w "wew" sedtext
wew

grep -n ".*" 显示行号输出 “.*” 代表任意字符

[root@localhost scripts]#grep  -n ".*" sedtext
1:qwerrrr
2:
3:wewq
4:wew1
5:erw
6:wew wweweweefd
7:wew weww
8:wew

grep -E 或egrep 可以使用正则表达

[root@localhost scripts]#egrep  -w "wew|fds" sedtext
wew wweweweefd
wew weww
wew
fds

猜你喜欢

转载自blog.csdn.net/LINU_BW/article/details/84894358