grep

grep  (Globally search a Regular Expression and Print)

文件test.txt的内容如下:

dlf test

dlfthink

www.baidu.com

TEST 123

Dlf's lemon

grep Grep

abc

abc123abc

123dlf123

[www.baidu.com]
View Code

grep -i "test" test.txt   

test.txt文件中搜索出“test”字符串,-i 不区分大小写

grep -i -n "test" test.txt  

-n 打印行号

grep -i -c "test" test.txt 

-c 打印匹配次数

grep -A1 "test" test.txt

-A1 打印出匹配行和下一行

grep -B1 "test" test.txt

-B 打印出匹配行和上一行

grep -C1 "test" test.txt

grep -C1 打印出匹配航和上一行和下一行

grep -w “test” test.txt 

-w 精确匹配“test”字符串

grep -v "test" test.txt 

匹配不包含“test”字符串的行

grep -e “test” -e “lest” test.txt

同时匹配“test” 和"lest" 字符串

 

posted @ 2020-09-24 19:50  vvf  阅读(146)  评论(0编辑  收藏  举报