當前位置:首頁 » 操作系統 » linuxforgrep

linuxforgrep

發布時間: 2025-01-25 12:19:40

linux:關於腳本for循環的執行順序

執行一次,for in 後邊的`` 或 $() 會產生一個list。然後依次讀取。

② linux命令里,grep * 是什麼意思

任意一個位元組 . 與重復位元組 *
這兩個符號在正則表達式的意義如下:
. (小數點):代表『一定有一個任意位元組』的意思;
* (星號):代表『重復前一個字元, 0 到無窮多次』的意思,為組合形態

假設我需要找出 g??d 的字串,亦即共有四個位元組, 起頭是 g 而結束是 d ,我可以這樣做:
[root@www ~]# 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".

因為強調 g 與 d 之間一定要存在兩個位元組,因此,第 13 行的 god 與第 14 行的 gd 就不會被列出來啦!

如果我想要列出有 oo, ooo, oooo 等等的數據, 也就是說,至少要有兩個(含) o 以上,該如何是好?
因為 * 代表的是『重復 0 個或多個前面的 RE 字元』的意義, 因此,『o*』代表的是:『擁有空位元組或一個 o 以上的位元組』,因此,『 grep -n 'o*' regular_express.txt 』將會把所有的數據都列印出來終端上!
當我們需要『至少兩個 o 以上的字串』時,就需要 ooo* ,亦即是:
[root@www ~]# grep -n 'ooo*' 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!

如果我想要字串開頭與結尾都是 g,但是兩個 g 之間僅能存在至少一個 o ,亦即是 gog, goog, gooog.... 等等,那該如何?
[root@www ~]# grep -n 'goo*g' regular_express.txt
18:google is the best tools for search keyword.
19:goooooogle yes!

如果我想要找出 g 開頭與 g 結尾的行,當中的字元可有可無
[root@www ~]# grep -n 'g.*g' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
14:The gd software is a library for drafting programs.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.

因為是代表 g 開頭與 g 結尾,中間任意位元組均可接受,所以,第 1, 14, 20 行是可接受的喔! 這個 .* 的 RE 表示任意字元是很常見的.

熱點內容
第一次使用微信支付密碼如何設定 發布:2025-05-07 06:57:16 瀏覽:816
幫助文檔網站源碼 發布:2025-05-07 06:57:10 瀏覽:97
linuxmysql資料庫重啟 發布:2025-05-07 06:50:24 瀏覽:522
安卓手機怎麼當電腦的揚聲器 發布:2025-05-07 06:43:57 瀏覽:838
域名訪問量統計 發布:2025-05-07 06:40:39 瀏覽:622
怎麼linux 發布:2025-05-07 06:40:33 瀏覽:690
ftp壓縮包怎麼導入 發布:2025-05-07 06:30:15 瀏覽:461
歐姆龍plc編程技巧 發布:2025-05-07 06:09:28 瀏覽:387
linux大寫轉小寫 發布:2025-05-07 06:09:27 瀏覽:750
怎麼識別是不是伺服器ip 發布:2025-05-07 06:00:18 瀏覽:853