中文字幕亚洲第一精品|精品国产免费一区二区|久久婷婷五月六月综合版|中文字幕熟妇久久久人妻|久久综合精品国产一区无码|国产成人精品永久免费视频|午夜亚洲国产精品理论片a级|久久精品一区二区三区无码护土

 訪問手機(jī)版  

Linux常用命令|Linux培訓(xùn)學(xué)習(xí)|考試認(rèn)證|工資待遇與招聘,認(rèn)準(zhǔn)超級(jí)網(wǎng)工!

招聘|合作 登陸|注冊(cè)

網(wǎng)絡(luò)工程師培訓(xùn)

當(dāng)前位置:網(wǎng)絡(luò)工程師 > 技術(shù)課程 > linux > 熱點(diǎn)關(guān)注 > linux常用命令

Linux常用基本命令:grep

時(shí)間:2019-09-13

linux常用shell命令_linux常用命令_linux壓縮命令zip命令

作用:從文本文件或管道數(shù)據(jù)流中篩選匹配的行及數(shù)據(jù),配合正則表達(dá)式一起使用,功能更加強(qiáng)大。

格式:

grep [options] [pattern] [file]

1,匹配包含"ghostwu"的行

ghostwu@dev:~/linux/grep$%20cat%20-n%20ghostwu.txt%20
%20%20%20%20%201%20%20%20%20my%20name%20is%20ghostwu
%20%20%20%20%202%20%20%20%20how%20are%20you
%20%20%20%20%203%20%20%20%20fine%20think%20you
%20%20%20%20%204%20%20%20%20My%20name%20is%20Ghostwu
%20%20%20%20%205%20%20%20%20what's%20your%20name?
%20%20%20%20%206%20%20%20%20my%20name%20is%20ghostwu2
%20%20%20%20%207%20%20%20%20
ghostwu@dev:~/linux/grep$%20grep%20"ghostwu"%20ghostwu.txt%20
my%20name%20is%20ghostwu
my%20name%20is%20ghostwu2

2,-v:%20不包含,相當(dāng)于取反

ghostwu@dev:~/linux/grep$%20grep%20-v%20"ghostwu"%20ghostwu.txt%20
how%20are%20you
fine%20think%20you
My%20name%20is%20Ghostwu
what's%20your%20name?

ghostwu@dev:~/linux/grep$%20

3,-n添加行號(hào)

ghostwu@dev:~/linux/grep$ grep -n "ghostwu" ghostwu.txt 
1:my name is ghostwu
6:my name is ghostwu2
ghostwu@dev:~/linux/grep$ grep -vn "ghostwu" ghostwu.txt 
2:how are you
3:fine think you
4:My name is Ghostwu
5:what's your name?
7:

4linux常用命令,-E,使用擴(kuò)展的egrep命令,模式中可以用正則表達(dá)式

ghostwu@dev:~/linux/grep$ cat ghostwu.txt 
my name is ghostwu
how are you
fine think you
My name is Ghostwu
what's your name?
my name is ghostwu2
ghostwu@dev:~/linux/grep$ grep -E "my|your" ghostwu.txt 
my name is ghostwu
what's your name?
my name is ghostwu2
ghostwu@dev:~/linux/grep$ grep -Ev "my|your" ghostwu.txt 
how are you
fine think you
My name is Ghostwu
ghostwu@dev:~/linux/grep$ grep -En "my|your" ghostwu.txt 
1:my name is ghostwu
5:what's your name?
6:my name is ghostwu2

5,-i選項(xiàng),不區(qū)分大小寫

linux常用shell命令_linux壓縮命令zip命令_linux常用命令

ghostwu@dev:~/linux/grep$ grep "ghostwu" ghostwu.txt 
my name is ghostwu
my name is ghostwu2
ghostwu@dev:~/linux/grep$ grep -i "ghostwu" ghostwu.txt 
my name is ghostwu
My name is Ghostwu
my name is ghostwu2