grep用法

grep是一个常用的命令。 以前只知道^$.+?*这些用法。以及-E的正则表达式。

今天偶然发现还有一些更高级的匹配模式。具体如下: [:alnum:]    字母与数字字符 [:alpha:]    字母 [:ascii:]    ASCII字符 [:blank:]    空格或制表符 [:cntrl:]    ASCII控制字符 [:digit:]    数字 [:graph:]    非控制,非空格字符 [:lower:]    小写字母 [:print:]    可打印字符 [:punct:]    标点符号字符 [:space:]    空白字符,包括垂直制表符 [:upper:]    大写字母 [:xdigit:]    十六进制数字 还有一些常用的就是 {n}            必须匹配n次 {n,}        必须匹配n次或n次以上 {n,m}        必须匹配n到m次,包含n和m 下面我们进行简单的测试下就知道了 文本内容如下test.txt ```c

A novel is a book of long narrative in literary prose The genre has historical roots both in the fields of the medieval and early modern romance and in the tradition of the novella The latter supplied the present generic term in the late 18th century. Further definition of the genre is historically difficult. The construction of the narrative, the plot, the way reality is created in the works of fiction. Most of these requirements were introduced in the 16th and 17th centuries in order to give fiction a justification outside the field of factual history. The individualism of the presentation makes the personal memoir and the autobiography the two closest relatives among the genres of modern histories.
c

grep a[[:blank:]] test.txt
![5561066808_a504984507_z.jpg](https://images.timoq.com/2011/03/5561066808_a504984507_z1.jpg "5561066808_a504984507_z.jpg")c

grep -E [a-z]{10} test.txt
![5561066804_ae4c0ebe60_z.jpg](https://images.timoq.com/2011/03/5561066804_ae4c0ebe60_z1.jpg "5561066804_ae4c0ebe60_z.jpg")c

grep Th.[[:space:]] test.txt