校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > 15個Linux Grep命令使用實(shí)例(實(shí)用、常用)

15個Linux Grep命令使用實(shí)例(實(shí)用、常用)

熱門標(biāo)簽:北京市地圖標(biāo)注 鹽城客服外呼系統(tǒng)軟件 鄭州營銷外呼系統(tǒng)運(yùn)營商 2020電銷機(jī)器人排行 廳外呼梯系統(tǒng)布線 貴陽語音電銷機(jī)器人招商 焦作人工智能電話機(jī)器人軟件 百度地圖標(biāo)注陰影動態(tài) 淘寶系統(tǒng)退貨外呼項(xiàng)目考試答案

Grep命令主要用于從文件中查找指定的字符串。
首先建一個demo_file:

復(fù)制代碼
代碼如下:

$ cat demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.

Two lines above this line is empty.
And this is the last line.

例01:從單個文件中查找指定的字符串

復(fù)制代碼
代碼如下:

$ grep "this" demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.

例02:從多個文件中查找指定的字符串

復(fù)制代碼
代碼如下:

$ cp demo_file demo_file1

$ grep "this" demo_*
demo_file:this line is the 1st lower case line in this file.
demo_file:Two lines above this line is empty.
demo_file:And this is the last line.
demo_file1:this line is the 1st lower case line in this file.
demo_file1:Two lines above this line is empty.
demo_file1:And this is the last line.

例03:忽略大小寫使用 grep -i

復(fù)制代碼
代碼如下:

$ grep -i "the" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
And this is the last line.

例04:在文件中匹配正則表達(dá)式

如果你能在實(shí)際使用正則表達(dá)式,能使效率大大提高。在下面的例子中,匹配了所有以lines開頭,以empty結(jié)尾的行。

復(fù)制代碼
代碼如下:

$ grep "lines.*empty" demo_file
Two lines above this line is empty.

從Grep文檔的來看,一個正則表達(dá)式必須遵循下面的匹配操作。
1.?         The preceding item is optional and matched at most once.
2.*          The preceding item will be matched zero or more times.
3.+         The preceding item will be matched one or more times.
4.{n}      The preceding item is matched exactly n times.
5.{n,}     The preceding item is matched n or more times.
6.{,m}    The preceding item is matched at most m times.
7.{n,m}  The preceding item is matched at least n times, but not more than m times.

例05:用grep -w來查找全匹配,不包括子字符串

比如說:用下面的例子搜索出來的例子包括"is","his"

復(fù)制代碼
代碼如下:

$ grep -i "is" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty.
And this is the last line.

而用grep -iw搜索出來的結(jié)果如下: 注意,忽略大小。"IS","is"

復(fù)制代碼
代碼如下:

$ grep -iw "is" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.

例06:用grep -A,-B,-C 來查看after/before/around 行
當(dāng)在一個大的文件中執(zhí)行g(shù)rep操作時,如果想要看其中一些行,并且想看之前,之后的或某些行附近的,那么這里命令就起作用了。grep -A,-B,-C.先建個demo.txt作為模板

復(fù)制代碼
代碼如下:

$ cat demo_text
4. Vim Word Navigation

You may want to do several navigation in relation to the words, such as:

* e - go to the end of the current word.
* E - go to the end of the current WORD.
* b - go to the previous (before) word.
* B - go to the previous (before) WORD.
* w - go to the next word.
* W - go to the next WORD.

WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.

 6.1 顯示匹配后N行
 

復(fù)制代碼
代碼如下:

$ grep -A 3 -i "example" demo_text
Example to show the difference between WORD and word

* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.

6.2 顯示匹配前N行

復(fù)制代碼
代碼如下:

$ grep -B 2 "single WORD" demo_text
Example to show the difference between WORD and word

* 192.168.1.1 - single WORD

6.3 顯示匹配前N行

復(fù)制代碼
代碼如下:

$ grep -C 2 "Example" demo_text
word - word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

* 192.168.1.1 - single WORD

例07:用GREP_OPTIONS來讓查找的項(xiàng)醒目

如果你想使匹配的好看且醒目,可以使用下面的操作:

復(fù)制代碼
代碼如下:

$ export GREP_OPTIONS='--color=auto' GREP_COLOR='100;8'

$ grep this demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.

例08:用grep -r來搜索所有的文件及子目錄

復(fù)制代碼
代碼如下:

$ grep -r "ramesh" *


例09:用grep -v來顯示不匹配的項(xiàng)

復(fù)制代碼
代碼如下:

$ grep -v "go" demo_text
4. Vim Word Navigation

You may want to do several navigation in relation to the words, such as:

WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.

例10:顯示所有不匹配的項(xiàng)

復(fù)制代碼
代碼如下:

$ cat test-file.txt
a
b
c
d

$ grep -v -e "a" -e "b" -e "c" test-file.txt
d

例11:用grep -c 來計(jì)算匹配的數(shù)量

11.1計(jì)算匹配的字符串?dāng)?shù)

復(fù)制代碼
代碼如下:

$ grep -c "go" demo_text
6

11.2計(jì)算匹配的模式數(shù)

復(fù)制代碼
代碼如下:

$ grep -c this demo_file
3

11.3計(jì)算不匹配的模式數(shù)

復(fù)制代碼
代碼如下:

$ grep -v -c this demo_file
4

例12:使用grep -l顯示匹配的文件名

復(fù)制代碼
代碼如下:

$ grep -l this demo_*
demo_file
demo_file1

例13:只顯示匹配的字符串

復(fù)制代碼
代碼如下:

$ grep -o "is.*line" demo_file
is line is the 1st lower case line
is line
is is the last line

例14:

復(fù)制代碼
代碼如下:

$ cat temp-file.txt1234512345
$ grep -o -b "3" temp-file.txt
2:3
8:3

注意:上述的不是該字符所在行中的位置,而是字節(jié)的位置。
例15:用grep -n 顯示行數(shù)

復(fù)制代碼
代碼如下:

$ grep -n "go" demo_text
5: * e - go to the end of the current word.
6: * E - go to the end of the current WORD.
7: * b - go to the previous (before) word.
8: * B - go to the previous (before) WORD.
9: * w - go to the next word.
10: * W - go to the next WORD.

標(biāo)簽:青島 周口 大慶 遼寧 大理 大興安嶺 六安 樂山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《15個Linux Grep命令使用實(shí)例(實(shí)用、常用)》,本文關(guān)鍵詞  15個,Linux,Grep,命令,使用,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《15個Linux Grep命令使用實(shí)例(實(shí)用、常用)》相關(guān)的同類信息!
  • 本頁收集關(guān)于15個Linux Grep命令使用實(shí)例(實(shí)用、常用)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃
    国产乱子伦视频一区二区三区 | 色成年激情久久综合| 亚洲国产日韩在线一区模特| 精品精品国产高清a毛片牛牛| www.色综合.com| 久久精品久久99精品久久| 国产精品久久久久久亚洲毛片 | 在线成人午夜影院| 成人av在线电影| 捆绑调教美女网站视频一区| 亚洲一区二区三区国产| 亚洲精品欧美二区三区中文字幕| 欧美日本在线播放| 色久优优欧美色久优优| 国产成人自拍高清视频在线免费播放| 亚洲国产精品久久久久婷婷884 | 国产欧美日韩视频一区二区| 欧美精品乱码久久久久久| aa级大片欧美| 久久av中文字幕片| 日韩av一区二区三区| 亚洲精品国产精华液| 久久人人97超碰com| 欧美一区二区三区免费| 欧美日韩一级视频| 在线一区二区三区四区五区| 不卡av在线网| 不卡影院免费观看| 成人午夜视频福利| 国产电影一区二区三区| 国模大尺度一区二区三区| 美日韩一级片在线观看| 日韩电影在线观看网站| 香蕉加勒比综合久久| 亚洲高清中文字幕| 亚洲一区二区欧美激情| 亚洲福中文字幕伊人影院| 亚洲一区二区三区四区的| 亚洲动漫第一页| 视频一区二区中文字幕| 丝袜国产日韩另类美女| 男人的天堂亚洲一区| 久久99精品久久久久久| 激情另类小说区图片区视频区| 精品一区二区影视| 国产高清成人在线| 高清久久久久久| 99久久免费视频.com| 欧美在线观看视频一区二区三区| 色网站国产精品| 欧美日韩久久一区二区| 欧美一区二区免费视频| 337p粉嫩大胆色噜噜噜噜亚洲| 久久综合国产精品| 国产精品乱码人人做人人爱| 国产精品视频看| 亚洲精品视频观看| 男女男精品视频| 国产综合久久久久久鬼色| 国产91精品露脸国语对白| 9l国产精品久久久久麻豆| 色香蕉成人二区免费| 3d成人动漫网站| 国产日韩欧美麻豆| 亚洲欧美日韩在线播放| 日韩精品色哟哟| 国产精品亚洲专一区二区三区| av网站一区二区三区| 欧美体内she精视频| 精品久久久久久久久久久久包黑料 | 韩国v欧美v日本v亚洲v| av在线不卡电影| 欧美日韩一区二区三区在线看| 日韩精品一区二区三区中文不卡| 国产亚洲精品7777| 一区二区高清在线| 国产综合成人久久大片91| 91浏览器入口在线观看| 国产精品久久久久久久久免费桃花 | 在线免费精品视频| 精品国产一区二区亚洲人成毛片| 国产精品久久久一本精品| 五月天亚洲婷婷| 成人午夜伦理影院| 欧美一区二区三区视频在线 | 另类欧美日韩国产在线| 粉嫩av亚洲一区二区图片| 8v天堂国产在线一区二区| 国产精品久久久久久久久久久免费看 | 91浏览器在线视频| 精品嫩草影院久久| 亚洲国产美国国产综合一区二区| 国产精品1区二区.| 欧美片网站yy| 亚洲国产精品成人综合| 蜜臀av性久久久久蜜臀aⅴ四虎| 99热在这里有精品免费| 精品国产一区二区三区不卡| 亚洲乱码一区二区三区在线观看| 九一九一国产精品| 欧美日韩午夜精品| 亚洲三级电影网站| 国产高清在线精品| 精品少妇一区二区三区日产乱码| 一区二区三区四区亚洲| 国产成人免费在线观看| 日韩欧美国产综合| 午夜精品视频一区| 色先锋资源久久综合| 国产精品理论在线观看| 国产一区二区导航在线播放| 欧美久久久久久久久中文字幕| 日韩一区欧美小说| 夫妻av一区二区| 精品国产一区二区三区av性色| 午夜影院在线观看欧美| 色婷婷久久久亚洲一区二区三区 | 成人性生交大片免费看中文| 日韩女优电影在线观看| 亚洲国产成人av好男人在线观看| 91网站视频在线观看| 国产日韩av一区| 国产一区二区导航在线播放| 精品少妇一区二区三区日产乱码 | 亚洲美女在线一区| va亚洲va日韩不卡在线观看| 国产偷v国产偷v亚洲高清| 国精产品一区一区三区mba视频 | 欧美视频一区二区三区四区| 亚洲免费在线电影| 色8久久精品久久久久久蜜| 亚洲欧美综合网| 色综合网站在线| 亚洲黄一区二区三区| 91国偷自产一区二区使用方法| 亚洲视频在线观看三级| 99热99精品| 亚洲色图欧美在线| 日本久久一区二区三区| 亚洲午夜久久久久久久久电影院| 欧美色欧美亚洲另类二区| 亚洲国产精品久久久男人的天堂| 欧美三级电影精品| 青青草91视频| 日韩欧美在线网站| 激情综合一区二区三区| 久久理论电影网| 成人一区二区三区在线观看| 亚洲视频免费观看| 国产精品视频你懂的| 色综合久久久久综合体| 亚洲丰满少妇videoshd| 欧美一区二区网站| 九九九久久久精品| 国产精品你懂的在线欣赏| 91丨porny丨首页| 亚洲国产婷婷综合在线精品| 91精品国产欧美日韩| 国产真实精品久久二三区| 欧美经典三级视频一区二区三区| 成人黄动漫网站免费app| 一区二区三区在线观看动漫| 欧美日本韩国一区二区三区视频| 另类综合日韩欧美亚洲| 中文字幕av一区二区三区免费看 | 天天亚洲美女在线视频| 亚洲精品在线观看视频| 成人激情图片网| 亚洲成av人片观看| 精品久久免费看| 91免费国产在线观看| 天使萌一区二区三区免费观看| 精品久久久久久久久久久久久久久 | 亚洲国产精品一区二区www在线| 日韩一区二区三区免费看 | 欧美在线观看视频在线| 久久99精品国产麻豆不卡| 日韩毛片一二三区| 欧美一区日韩一区| 欧美卡1卡2卡| 国产高清精品网站| 亚洲成人一区二区| 国产欧美一区二区精品久导航| 色综合久久综合网97色综合 | 一区二区久久久久| 欧美岛国在线观看| 91久久精品一区二区| 麻豆国产精品视频| 一区二区欧美视频| 国产无人区一区二区三区| 欧美精品一二三区| 波多野结衣中文一区| 麻豆精品久久久| 亚洲最新视频在线观看| 久久九九99视频| 欧美久久婷婷综合色| 99久久免费精品高清特色大片| 久久成人av少妇免费| 亚洲在线中文字幕| 国产精品久久久久久久第一福利|