Linux系列shell編程之文檔操作(3)

      網友投稿 764 2022-05-29

      一、正則表達式和通配符

      // 本章知識點講解文件如下:文件格式不要動,就是這樣。 [root@image1 ~]# cat test_rule.sh Mr. Zhang San said; he was the hones man in LampBrother. 123despise him. But since Mr. Li Si came, he never saaaid those words. 5555nice! because, actuaaaally, Mr. Li Si is the most honest man Later, Mr. Zhang San soid his hot body.

      1)linux中支持的通配符

      * 代表任意字符重復任意多次; ? 代表任意字符重復一次; [] 代表匹配[]中所寫的任意一個字符;

      * 前一個字符匹配0次,或任意多次。 . 匹配除了換行符外,任意一個字符。 ^ 匹配行首。【^hello匹配以hello開頭的行】 $ 匹配行尾?!緃ello$匹配以hello結尾的行】 [] 匹配中括號中指定的任意一個字符,只匹配一個字符。 [^] 取反。匹配除中括號的字符以外的任意一個字符。 \ 轉義符。取消特殊符號的含義,變為普通字符。 \{n\} 表示其前面的字符恰好出現n次。[0-9]\{4\}匹配4位數字 \{n,\} 表示其前面的字符出現不小于n次。[0-9]\{2,\}匹配2位及以上數字 \{n,m\} 表示其前面的字符至少出現n次,最多出現m次。

      // 這樣寫是匹配所有內容,包括空白行 [root@image1 ~]# grep "a*" test_rule.sh // 匹配至少有一個a的行 [root@image1 ~]# grep "aa*" test_rule.sh // 匹配最少包含兩個連續a的行 [root@image1 ~]# grep "aaa*" test_rule.sh // 匹配最少包含四個連續a的行 [root@image1 ~]# grep "aaaa*" test_rule.sh

      // 匹配在s、d這兩個字母之間一定有兩個字符的單詞 [root@image1 ~]# grep "s..d" test_rule.sh Mr. Zhang San said; Later, Mr. Zhang San soid his hot body. // 匹配在s、d字母之間有在意字符 [root@image1 ~]# grep "s.*d" test_rule.sh Mr. Zhang San said; he never saaaid those words. Later, Mr. Zhang San soid his hot body. // 匹配所有內容 [root@image1 ~]# grep ".*" test_rule.sh

      Linux系列:shell編程之文檔操作(3)

      // 匹配以大寫“M”開頭的行 [root@image1 ~]# grep "^M" test_rule.sh Mr. Zhang San said; Mr. Li Si is the most honest man // 匹配以小寫“n”結尾的行 [root@image1 ~]# grep "n$" test_rule.sh Mr. Li Si is the most honest man // 匹配空白行。-n表示顯示匹配的是哪一行。 [root@image1 ~]# grep -n "^$" test_rule.sh 7: [root@image1 ~]#

      // 匹配s和id中,有一個a或者有一個o的行 [root@image1 ~]# grep "s[ao]id" test_rule.sh Mr. Zhang San said; Later, Mr. Zhang San soid his hot body. // 匹配帶有一個數字的行 [root@image1 ~]# grep "[0-9]" test_rule.sh 123despise him. 5555nice! // 匹配不帶有一個數字的行 [root@image1 ~]# grep "[^0-9]" test_rule.sh

      // 匹配不用小寫字母開頭的行 [root@image1 ~]# grep "^[^a-z]" test_rule.sh Mr. Zhang San said; 123despise him. But since Mr. Li Si came, 5555nice! Mr. Li Si is the most honest man Later, Mr. Zhang San soid his hot body. // 匹配不用字母開頭的行 [root@image1 ~]# grep "^[^a-zA-Z]" test_rule.sh 123despise him. 5555nice!

      // 匹配使用“.”結尾的行 [root@image1 ~]# grep "\.$" test_rule.sh he was the hones man in LampBrother. 123despise him. he never saaaid those words. Later, Mr. Zhang San soid his hot body.

      // 匹配a字母連續出現三次的字符串 [root@image1 ~]# grep "a\{3\}" test_rule.sh he never saaaid those words. because, actuaaaally, // 匹配包含連續的四個數字的字符串 [root@image1 ~]# grep "[0-9]\{4\}" test_rule.sh 5555nice!

      // 匹配至少以三個連續數字開頭的字符串。 [root@image1 ~]# grep "^[0-9]\{3,\}" test_rule.sh 123despise him. 5555nice!

      // 匹配在字母s和字母i之間有最少一個a,最多三個a的行 [root@image1 ~]# grep "sa\{1,3\}i" test_rule.sh Mr. Zhang San said; he never saaaid those words. // 匹配在字母s和字母i之間有最少一個a,最多兩個a的行 [root@image1 ~]# grep "sa\{1,2\}i" test_rule.sh Mr. Zhang San said;

      Linux Shell

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:Google鼓勵的13條代碼審查標準
      下一篇:Linux系列:shell編程之文檔操作(2)
      相關文章
      亚洲一日韩欧美中文字幕在线| 亚洲人妖女同在线播放| 亚洲一区精彩视频| 久久亚洲精品成人无码网站| 图图资源网亚洲综合网站| 久久亚洲高清观看| 国产AV无码专区亚洲AV男同 | 亚洲VA中文字幕不卡无码| 亚洲人色婷婷成人网站在线观看 | 亚洲午夜电影在线观看| 亚洲神级电影国语版| 亚洲酒色1314狠狠做| 亚洲精彩视频在线观看| 亚洲第一二三四区| 亚洲一本之道高清乱码| 亚洲欧洲日韩极速播放 | 久99精品视频在线观看婷亚洲片国产一区一级在线 | 亚洲熟妇无码av另类vr影视| 亚洲最大中文字幕无码网站| 亚洲一本到无码av中文字幕| 亚洲精品国产第一综合99久久| 亚洲av永久中文无码精品| 国产精品亚洲综合天堂夜夜| avtt亚洲天堂| 狠狠亚洲狠狠欧洲2019| 亚洲av无码乱码国产精品| 久久丫精品国产亚洲av不卡| 亚洲系列国产精品制服丝袜第| 亚洲AV无码专区在线亚| 亚洲欧美中文日韩视频| 无码国产亚洲日韩国精品视频一区二区三区 | 亚洲人成电影网站国产精品 | 久久久影院亚洲精品| 亚洲精品午夜久久久伊人| 亚洲人xxx日本人18| 亚洲AV无码一区二区三区久久精品| 国产亚洲午夜精品| 在线观看午夜亚洲一区| 亚洲国产成人私人影院| 亚洲乱码日产精品BD在线观看| 亚洲欧美第一成人网站7777 |