1. 程式人生 > >grep 命令使用(2)

grep 命令使用(2)

grep 引數-w 精準匹配查詢的內容並輸出所在行

[[email protected] scripts]#cat sedtext
qwerrrr
wewq
wew1
erw
wew
[[email protected] scripts]#grep "wew" sedtext
wewq
wew1
wew

[[email protected] scripts]#grep  -w "wew" sedtext
wew

grep -n ".*" 顯示行號輸出 “.*” 代表任意字元

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

grep -E 或egrep 可以使用正則表達

[[email protected] scripts]#egrep  -w "wew|fds" sedtext
wew wweweweefd
wew weww
wew
fds