不卡AV在线|网页在线观看无码高清|亚洲国产亚洲国产|国产伦精品一区二区三区免费视频

學習啦>學習電腦>操作系統(tǒng)>Linux教程>

linux中的grep命令的用法詳解(2)

時間: 佳洲1085 分享

  查找非小寫字母加oo的內(nèi)容

  [root@ www.linuxidc.com]# grep -n '[^a-z]oo' regular_express.txt

  3:Football game is not use feet only.

  獲取有數(shù)字的一行

  [root@ www.linuxidc.com]# grep -n '[0-9]' regular_express.txt

  5:However, this dress is about $ 3183 dollars.

  15:You are the best is mean you are the no. 1.

  [root@ www.linuxidc.com]# grep -n '[^[:lower:]]oo' regular_express.txt

  3:Football game is not use feet only.

  查詢以the開頭的字符

  [root@ www.linuxidc.com]# grep -n '^the' regular_express.txt

  12:the symbol '*' is represented as start.

  查詢開頭是小寫字母的內(nèi)容

  [root@ www.linuxidc.com]# grep -n '^[a-z]' regular_express.txt

  2:apple is my favorite food.

  4:this dress doesn't fit me.

  10:motorcycle is cheap than car.

  12:the symbol '*' is represented as start.

  18:google is the best tools for search keyword.

  19:goooooogle yes!

  20:go! go! Let's go.

  查詢第一個字符不是大寫的

  [root@ www.linuxidc.com]# grep -n '^[[:lower:]]' regular_express.txt

  2:apple is my favorite food.

  4:this dress doesn't fit me.

  10:motorcycle is cheap than car.

  12:the symbol '*' is represented as start.

  18:google is the best tools for search keyword.

  19:goooooogle yes!

  20:go! go! Let's go.

  查詢不是以英文開頭的字符

  [root@ www.linuxidc.com]# grep -n '^[^a-zA-Z]' regular_express.txt

  1:"Open Source" is a good mechanism to develop programs.

  21:# I am VBird

  查詢結(jié)尾是小數(shù)點的行的內(nèi)容.

  [root@ www.linuxidc.com]# grep -n '\.$' regular_express.txt

  1:"Open Source" is a good mechanism to develop programs.

  2:apple is my favorite food.

  3:Football game is not use feet only.

  4:this dress doesn't fit me.

  10:motorcycle is cheap than car.

  11:This window is clear.

  12:the symbol '*' is represented as start.

  15:You are the best is mean you are the no. 1.

  16:The world <Happy> is the same with "glad".

  17:I like dog.

  18:google is the best tools for search keyword.

  20:go! go! Let's go.

  查找“空白行”

  [root@ www.linuxidc.com]# grep -n '^$' regular_express.txt

  22:

  通配符.和*的使用,.(小數(shù)點)代表一定有一個任意字符,*代表重復前一個到無窮多次的意思

  [root@ www.linuxidc.com]# grep -n 'g..d' regular_express.txt

  1:"Open Source" is a good mechanism to develop programs.

  9:Oh! The soup taste good.

  16:The world <Happy> is the same with "glad".

  查詢出現(xiàn)任意數(shù)字的行列

  [root@ www.linuxidc.com]# grep -n '[0-9][0-9]*' regular_express.txt

  5:However, this dress is about $ 3183 dollars.

  15:You are the best is mean you are the no. 1.

  查詢出現(xiàn)兩個o的字符串

  [root@ www.linuxidc.com]# grep -n 'o\{2\}' regular_express.txt

  1:"Open Source" is a good mechanism to develop programs.

  2:apple is my favorite food.

  3:Football game is not use feet only.

  9:Oh! The soup taste good.

  18:google is the best tools for search keyword.

  19:goooooogle yes!

  查詢出現(xiàn)2-5個o的字符串,后面在接一個g的字符串

  [root@ www.linuxidc.com]# grep -n 'o\{2,5\}g' regular_express.txt

  18:google is the best tools for search keyword.

  19:goooooogle yes!

  查詢出現(xiàn)2個以上o的字符串,后面在接一個g的字符串

  [root@ www.linuxidc.com]# grep -n 'o\{2,\}g' regular_express.txt

  18:google is the best tools for search keyword.

  19:goooooogle yes!

  三、擴展資料:linux中g(shù)rep命令之正則表達式

  匹配字符:這部分和基本正則表達式一樣

  匹配次數(shù):

  * :和基本正則表達式一樣

  ? :基本正則表達式是\?,二這里沒有\(zhòng)。

  {m,n} :相比基本正則表達式也是沒有了\。

  + :匹配其前面的字符至少一次,相當于{1,}。

  位置錨定:和基本正則表達式一樣。

  分組及引用:

  (string) :相比基本正則表達式也是沒有了\。

   class="main">

linux中的grep命令的用法詳解(2)

時間: 佳洲1085 分享

  或者:

  a|b :匹配a或b,注意a是指 | 的左邊的整體,b也同理。比如 C|cat 表示的是 C或cat,而不是Cat或cat,如果要表示Cat或cat,則應(yīng)該寫為 (C|c)at 。記住(string)除了用于引用還用于分組。

  常用正則表達式部分就說到這里,以后用到在另行補充,如果你有興趣也可以去網(wǎng)上查找其他文章來進一步了解。

3635303