婷婷综合国产,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视频精品在线| 欧美亚洲愉拍一区二区| 亚洲成人免费视频| 国产麻豆视频精品| 中文字幕一区视频| 欧美精品一区二区三区蜜臀| 国产精品影视在线观看| 中文字幕巨乱亚洲| 日韩av不卡一区二区| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 成人免费va视频| 一区二区在线观看视频| 国产成人亚洲综合a∨婷婷 | 3atv在线一区二区三区| 国产最新精品免费| 欧美国产精品专区| 国产丶欧美丶日本不卡视频| 激情另类小说区图片区视频区| caoporen国产精品视频| 亚洲高清免费在线| 亚洲国产日日夜夜| 久久久精品黄色| 偷拍一区二区三区| 国产亚洲va综合人人澡精品| 国产成人99久久亚洲综合精品| 国产精品系列在线| 色噜噜狠狠成人网p站| 成人免费不卡视频| 欧美日韩一本到| 高清在线观看日韩| 国产视频一区在线观看 | 欧美日韩高清一区二区三区| 亚洲视频香蕉人妖| 欧美刺激午夜性久久久久久久 | 国产蜜臀av在线一区二区三区| 91丨九色丨国产丨porny| 国产精品久久久久影院亚瑟| 91精品国产综合久久福利软件| 久久久久久久综合| 欧美一卡二卡三卡| 欧美中文一区二区三区| 亚洲国产成人91porn| 免费高清在线视频一区·| 欧美精品一区二区三| av欧美精品.com| 精品裸体舞一区二区三区| 婷婷激情综合网| 亚洲视频一区在线观看| 一本久道中文字幕精品亚洲嫩| 激情综合五月婷婷| 亚洲欧美一区二区不卡| 成人av网址在线| 国产大片一区二区| 久久综合久久综合久久| 日韩免费视频线观看| 蜜臀99久久精品久久久久久软件| 一片黄亚洲嫩模| 久久精品日韩一区二区三区| 成人高清视频免费观看| 视频一区视频二区中文| 免费观看久久久4p| 视频在线观看一区| 精品国产乱码久久| 国产精品灌醉下药二区| 日韩欧美精品在线视频| 欧美经典三级视频一区二区三区| 91亚洲精品久久久蜜桃网站| 欧美韩国一区二区| 亚洲r级在线视频| 久久亚洲影视婷婷| 99久久精品久久久久久清纯| 国内精品不卡在线| 久久综合九色综合97婷婷女人| 日韩女优av电影| 亚洲成人福利片| 日韩精品五月天| 日韩精品一级中文字幕精品视频免费观看 | 日韩欧美国产1| 欧美日本高清视频在线观看| 韩国一区二区视频| 99久久久精品| 欧美片在线播放| 亚洲成人黄色影院| 日本成人中文字幕| 老司机午夜精品99久久| 国产亚洲欧美在线| 欧美日韩一区二区三区四区| 国产精品影视在线| 日日夜夜精品免费视频| 国产精品九色蝌蚪自拍| 欧美精品 日韩| 99精品久久免费看蜜臀剧情介绍| 玖玖九九国产精品| 欧美国产乱子伦| 国产精品人成在线观看免费 | 国产一区二区免费在线| 国产精品888| 国产不卡免费视频| 午夜精品视频一区| 日韩高清一区在线| 欧美日本高清视频在线观看| 日韩午夜三级在线| 国产亚洲成av人在线观看导航| 欧美一区中文字幕| 国产日产欧产精品推荐色| av午夜一区麻豆| 欧美精选一区二区| 久久免费午夜影院| 日韩一区二区在线观看视频| 国产三级精品三级| aaa亚洲精品| 51午夜精品国产| 亚洲国产精品ⅴa在线观看| av不卡免费在线观看| 国产无一区二区| 欧美性videosxxxxx| 69av一区二区三区| 欧美午夜精品久久久久久超碰| 日韩精品中文字幕一区二区三区| 麻豆视频一区二区| 国产一区91精品张津瑜| 91蜜桃在线免费视频| heyzo一本久久综合| 在线综合视频播放| 中文无字幕一区二区三区| 欧美激情一区二区三区在线| 亚洲成在人线在线播放| 亚洲午夜精品久久久久久久久| 国产麻豆一精品一av一免费 | 中文字幕制服丝袜成人av| 欧美在线一区二区三区| 99久久精品99国产精品| 99九九99九九九视频精品| 欧美第一区第二区| 日韩欧美的一区| 91精品国产乱码| 波多野结衣中文字幕一区二区三区 | 69久久夜色精品国产69蝌蚪网| 国产精品欧美综合在线| 精品美女一区二区| 五月天欧美精品| 99r精品视频| 一本色道综合亚洲| 国产欧美精品区一区二区三区| 久久新电视剧免费观看| 日韩精品电影在线观看| 91欧美一区二区| 欧美片网站yy| 亚洲chinese男男1069| 制服丝袜日韩国产| 亚洲一区二区免费视频| 99在线精品一区二区三区| 在线看国产日韩| 欧美精品v国产精品v日韩精品| 精品久久久久久无| 欧美韩国一区二区| 欧美日韩一区高清| 91在线丨porny丨国产| 3d动漫精品啪啪一区二区竹菊 | 亚洲国产成人porn| 午夜精品福利一区二区三区av | 国产91精品精华液一区二区三区| 成人黄色免费短视频| 日韩你懂的在线播放| 日韩精品一级二级| 91麻豆产精品久久久久久| 亚洲国产精品v| 国产精品综合在线视频| 2020国产精品| 蜜臀av一区二区在线观看| 91精品久久久久久蜜臀| 亚洲综合免费观看高清完整版| 免费在线观看精品| 日韩欧美成人午夜| 午夜免费久久看| 欧美一区二区视频免费观看| 一区二区三区在线观看国产| 一本色道久久综合亚洲精品按摩| 日本一区二区不卡视频| 成人黄动漫网站免费app| 欧美精品一区视频| 国产精品一级片在线观看| 欧美成人aa大片| 激情亚洲综合在线| 26uuu久久天堂性欧美| 国产91精品在线观看| 久久精品视频一区二区三区| 国产美女一区二区| 国产亚洲欧美激情| 国产成人综合在线观看| 国产农村妇女毛片精品久久麻豆| 视频一区欧美精品| 成人小视频免费在线观看| 欧美性视频一区二区三区| 亚洲欧美日韩国产手机在线| 91亚洲大成网污www| 亚洲精品一区二区三区香蕉|