當前位置:首頁 » 操作系統 » 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 表示任意字元是很常見的.

熱點內容
android自啟動服務 發布:2025-08-28 06:36:14 瀏覽:825
真實戰爭安卓手機怎麼安裝內存卡 發布:2025-08-28 06:22:52 瀏覽:172
上海雲伺服器訂餐 發布:2025-08-28 06:22:46 瀏覽:920
購買伺服器如何付款 發布:2025-08-28 06:22:10 瀏覽:966
FTP獵頭 發布:2025-08-28 05:55:29 瀏覽:486
顆粒壓壓縮機 發布:2025-08-28 05:54:08 瀏覽:602
數控編程F的意思 發布:2025-08-28 05:31:58 瀏覽:259
python的平方 發布:2025-08-28 05:20:35 瀏覽:643
東莞壓縮彈簧廠 發布:2025-08-28 05:14:06 瀏覽:792
c語言inout 發布:2025-08-28 05:02:57 瀏覽:917