婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

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

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

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

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

復制代碼
代碼如下:

$ 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:從單個文件中查找指定的字符串

復制代碼
代碼如下:

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

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

復制代碼
代碼如下:

$ 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

復制代碼
代碼如下:

$ 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:在文件中匹配正則表達式

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

復制代碼
代碼如下:

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

從Grep文檔的來看,一個正則表達式必須遵循下面的匹配操作。
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"

復制代碼
代碼如下:

$ 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搜索出來的結果如下: 注意,忽略大小。"IS","is"

復制代碼
代碼如下:

$ 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 行
當在一個大的文件中執行grep操作時,如果想要看其中一些行,并且想看之前,之后的或某些行附近的,那么這里命令就起作用了。grep -A,-B,-C.先建個demo.txt作為模板

復制代碼
代碼如下:

$ 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行
 

復制代碼
代碼如下:

$ 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行

復制代碼
代碼如下:

$ 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行

復制代碼
代碼如下:

$ 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來讓查找的項醒目

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

復制代碼
代碼如下:

$ 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來搜索所有的文件及子目錄

復制代碼
代碼如下:

$ grep -r "ramesh" *


例09:用grep -v來顯示不匹配的項

復制代碼
代碼如下:

$ 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:顯示所有不匹配的項

復制代碼
代碼如下:

$ cat test-file.txt
a
b
c
d

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

例11:用grep -c 來計算匹配的數量

11.1計算匹配的字符串數

復制代碼
代碼如下:

$ grep -c "go" demo_text
6

11.2計算匹配的模式數

復制代碼
代碼如下:

$ grep -c this demo_file
3

11.3計算不匹配的模式數

復制代碼
代碼如下:

$ grep -v -c this demo_file
4

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

復制代碼
代碼如下:

$ grep -l this demo_*
demo_file
demo_file1

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

復制代碼
代碼如下:

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

例14:

復制代碼
代碼如下:

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

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

復制代碼
代碼如下:

$ 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.

標簽:青島 周口 大慶 遼寧 大理 大興安嶺 六安 樂山

巨人網絡通訊聲明:本文標題《15個Linux Grep命令使用實例(實用、常用)》,本文關鍵詞  15個,Linux,Grep,命令,使用,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《15個Linux Grep命令使用實例(實用、常用)》相關的同類信息!
  • 本頁收集關于15個Linux Grep命令使用實例(實用、常用)的相關信息資訊供網民參考!
  • 推薦文章
    婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av
    亚洲手机成人高清视频| 亚洲尤物视频在线| 久久99精品久久久久久动态图 | 国产主播一区二区三区| 性做久久久久久| 亚洲精品久久7777| 亚洲九九爱视频| 亚洲高清在线精品| 日韩av午夜在线观看| 日本va欧美va瓶| 狠狠色丁香久久婷婷综合_中| 极品美女销魂一区二区三区| 国产精品99久久久久久宅男| 国产成人精品免费在线| 中文字幕欧美一| 一区二区三区四区精品在线视频| 亚洲三级久久久| 五月婷婷综合激情| 久久精品国产免费| 成人va在线观看| 日本高清不卡一区| 欧美一区二区三区四区高清 | 成人av电影在线网| 一本久久a久久精品亚洲| 欧美性感一区二区三区| 欧美一区二区大片| 国产日本一区二区| 肉肉av福利一精品导航| 国产成人高清在线| 欧美日韩情趣电影| 国产欧美日韩综合| 一区二区三区高清不卡| 国产乱码精品一区二区三| 丁香六月综合激情| 国产在线麻豆精品观看| 美女免费视频一区二区| 国产在线精品免费av| 国产91对白在线观看九色| 欧美在线免费播放| 久久精品人人做人人爽97 | 国产91综合一区在线观看| 91电影在线观看| 亚洲精品在线电影| 亚洲成人久久影院| a级精品国产片在线观看| 精品久久久久一区| 亚洲福中文字幕伊人影院| 国产黄色精品视频| 777精品伊人久久久久大香线蕉| 国产欧美一区二区三区在线老狼| 五月激情综合网| 精品国产乱码久久久久久久| 欧美日韩亚洲高清一区二区| 日韩一区二区三区四区| 亚洲丝袜精品丝袜在线| 寂寞少妇一区二区三区| 欧美视频一区在线| 亚洲婷婷在线视频| 成人精品视频一区二区三区 | 91一区二区在线| 日韩女优制服丝袜电影| 亚洲va欧美va天堂v国产综合| 丁香婷婷深情五月亚洲| 久久久国产一区二区三区四区小说| 视频一区在线播放| 欧美日韩在线一区二区| 亚洲高清免费视频| 91黄色在线观看| 亚洲婷婷综合色高清在线| 成人午夜激情在线| 久久久久久久久99精品| 国产精品1区2区3区| 久久久久久9999| 成人午夜激情片| 国产精品久久久久久久久果冻传媒| 久久99热99| 欧美不卡一区二区三区四区| 久久99精品久久久| 精品噜噜噜噜久久久久久久久试看| 日本成人在线不卡视频| 欧美一区二区三区日韩| 丝袜a∨在线一区二区三区不卡| 欧美日韩国产经典色站一区二区三区| 亚洲小少妇裸体bbw| 在线电影欧美成精品| 三级久久三级久久久| 精品欧美一区二区在线观看| 久久av中文字幕片| 亚洲国产成人自拍| 99国产精品久久久久久久久久久| 亚洲伦在线观看| 91精品蜜臀在线一区尤物| 美女一区二区三区在线观看| 久久尤物电影视频在线观看| 国产成人一区在线| 自拍偷拍国产精品| 欧美一级黄色片| 从欧美一区二区三区| 亚洲一区自拍偷拍| 欧美mv日韩mv国产网站| 大胆亚洲人体视频| 亚洲国产精品久久艾草纯爱| 精品美女一区二区| 99精品热视频| 九九久久精品视频| 国产精品电影院| 日韩一区二区在线免费观看| 成人免费观看视频| 日韩综合小视频| 国产精品护士白丝一区av| 91精品国产aⅴ一区二区| 国产福利不卡视频| 日韩影院免费视频| 中文字幕的久久| 精品日产卡一卡二卡麻豆| 色综合天天综合给合国产| 激情六月婷婷久久| 一区二区成人在线视频| xfplay精品久久| 欧美日本视频在线| 色综合久久中文字幕| 国产成人在线色| 久久福利资源站| 亚洲一区二区三区在线看| 国产精品免费久久| 日韩精品一区二区在线| 欧美麻豆精品久久久久久| 91视频观看视频| 国产91精品一区二区麻豆亚洲| 日本成人在线看| 亚洲福利一二三区| 亚洲一区免费观看| 一区二区三区久久| 亚洲美女精品一区| 亚洲精品欧美二区三区中文字幕| 国产三级精品在线| 亚洲精品在线观看网站| 精品成人免费观看| 精品久久久久久最新网址| 欧美群妇大交群的观看方式| 欧美日韩情趣电影| 欧美亚洲国产一区在线观看网站| 在线亚洲人成电影网站色www| 99久久国产综合色|国产精品| 成人污污视频在线观看| 国产成人av在线影院| 国产麻豆午夜三级精品| 国产一区二区三区免费播放 | 亚洲综合丁香婷婷六月香| 综合中文字幕亚洲| 亚洲欧美日韩电影| 亚洲老司机在线| 亚洲乱码国产乱码精品精小说| 亚洲精品国产视频| 亚洲综合999| 丝袜美腿高跟呻吟高潮一区| 日韩av电影免费观看高清完整版 | 99久久婷婷国产| 91小宝寻花一区二区三区| 99精品视频免费在线观看| 99vv1com这只有精品| 欧美日产在线观看| 日韩精品一区二区三区视频在线观看 | 成人小视频免费在线观看| 成人激情开心网| 色菇凉天天综合网| 日韩小视频在线观看专区| 久久老女人爱爱| 亚洲色图视频网| 日韩影院精彩在线| 粉嫩久久99精品久久久久久夜| 日本二三区不卡| 日韩视频国产视频| 中文字幕制服丝袜一区二区三区| 亚洲男人电影天堂| 麻豆久久久久久| 成人免费视频app| 制服丝袜激情欧洲亚洲| 国产亚洲一二三区| 亚洲国产精品一区二区久久恐怖片 | 天天综合天天做天天综合| 国产一区三区三区| 色999日韩国产欧美一区二区| 91精品国产综合久久精品| 国产亚洲欧美一级| 亚洲h在线观看| 国产成人自拍高清视频在线免费播放| 欧洲亚洲国产日韩| 久久影院午夜片一区| 亚洲成人自拍偷拍| www.久久久久久久久| 日韩免费一区二区| 亚洲精品日韩专区silk| 国产a区久久久| 日韩视频免费直播| 亚洲自拍偷拍综合| aaa欧美色吧激情视频| 久久精品夜色噜噜亚洲aⅴ| 亚洲成人激情自拍| 色综合激情久久|