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
本文深入讲解了如何使用grep命令进行精确查找,包括使用-w参数进行全词匹配,使用-n参数显示行号,以及如何利用egrep或grep -E进行正则表达式的高级搜索。通过实例演示,读者可以学习到grep在Linux或Unix系统中高效查找文件内容的方法。
4万+

被折叠的 条评论
为什么被折叠?



