首页 > Linux操作系统 > Linux操作系统 > grep command
| 特殊符號 | 代表意義 |
| [:alnum:] | 代表英文大小寫字元及數字,亦即 0-9, A-Z, a-z |
| [:alpha:] | 代表任何英文大小寫字元,亦即 A-Z, a-z |
| [:blank:] | 代表空白鍵與 [Tab] 按鍵兩者 |
| [:cntrl:] | 代表鍵盤上面的控制按鍵,亦即包括 CR, LF, Tab, Del.. 等等 |
| [:digit:] | 代表數字而已,亦即 0-9 |
| [:graph:] | 除了空白字元 (空白鍵與 [Tab] 按鍵) 外的其他所有按鍵 |
| [:lower:] | 代表小寫字元,亦即 a-z |
| [:print:] | 代表任何可以被列印出來的字元 |
| [:punct:] | 代表標點符號 (punctuation symbol),亦即:" ' ? ! ; : # $... |
| [:upper:] | 代表大寫字元,亦即 A-Z |
| [:space:] | 任何會產生空白的字元,包括空白鍵, [Tab], CR 等等 |
| [:xdigit:] | 代表 16 進位的數字類型,因此包括: 0-9, A-F, a-f 的數字與字元 |
但是,如果我不想要 oo 前面有 g 的話呢?此時,可以利用在集合字元的反向選擇 [^] 來達成:
[root@www ~]# grep -n '[^g]oo' regular_express.txt 2:apple is my favorite food. 3:Football game is not use feet only. 18:google is the best tools for search keyword. 19:goooooogle yes! |
這樣講不好懂,我們直接做個練習吧!假設我需要找出 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 |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28193163/viewspace-744919/ ,如需转载,请注明出处,否则将追究法律责任。