{"id":112714,"date":"2018-07-30T08:47:59","date_gmt":"2018-07-30T00:47:59","guid":{"rendered":"https:\/\/gulass.cn\/?p=112714"},"modified":"2018-07-25T09:49:18","modified_gmt":"2018-07-25T01:49:18","slug":"linux-grep-rex","status":"publish","type":"post","link":"https:\/\/gulass.cn\/linux-grep-rex.html","title":{"rendered":"\u5728Linux\u4e2d\u4f7f\u7528grep\u6b63\u5219\u8868\u8fbe\u5f0f\u5165\u95e8"},"content":{"rendered":"
\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u7b26\u53f7\u8868\u793a\u6cd5\uff0c\u7528\u4e8e\u8bc6\u522b\u6587\u672c\u6a21\u5f0f\u3002Linux\u5904\u7406\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u4e3b\u8981\u7a0b\u5e8f\u662fgrep\u3002grep\u641c\u7d22\u4e0e\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7684\u884c\uff0c\u5e76\u5c06\u7ed3\u679c\u8f93\u9001\u81f3\u6807\u51c6\u8f93\u51fa\u3002<\/p>\n
grep\u6309\u4e0b\u8ff0\u65b9\u5f0f\u63a5\u53d7\u9009\u9879\u548c\u53c2\u6570(\u5176\u4e2d\uff0cregex\u8868\u793a\u6b63\u5219\u8868\u8fbe\u5f0f)<\/p>\n
grep [options] regex [files]<\/p>\n
\u5176\u4e2doptions\u4e3b\u8981\u4e3a\u4e0b\u8868\uff1a<\/p>\n
\r\n\r\n\u9009\u9879\t\u542b\u4e49\t\u529f\u80fd\u63cf\u8ff0\r\n-i\tignore case\t\u5ffd\u7565\u5927\u5c0f\u5199\r\n-v\tinvert match\t\u4e0d\u5339\u914d\u5339\u914d\u7684\r\n-l\tfile-with-match\t\u8f93\u51fa\u5339\u914d\u7684\u6587\u4ef6\u540d\r\n-L\tfile-without-match\t\u8f93\u51fa\u4e0d\u5339\u914d\u7684\u6587\u4ef6\u540d\r\n-c\tcount\t\u8f93\u51fa\u5339\u914d\u7684\u6570\u76ee\uff08\u884c\u6570\uff09\r\n-n\tnumber\t\u8f93\u51fa\u5339\u914d\u884c\u7684\u540c\u65f6\u5728\u524d\u9762\u52a0\u4e0a\u6587\u4ef6\u540d\u53ca\u5728\u6587\u4ef6\u540d\u4e2d\u7684\u884c\u6570\r\n-h\tno-filename\t\u6291\u5236\u6587\u4ef6\u540d\u7684\u8f93\u51fa\r\n<\/pre>\n\u4e3e\u4f8b\u8bf4\u660e<\/strong><\/p>\n
\u5047\u8bbe\u6709\u4e09\u4e2a\u6587\u4ef6del1\u3001del2\u3001del3\u4e09\u4e2a\u6587\u4ef6\u7684\u5185\u5bb9\u5982\u4e0b
\n<\/p>\n\u4f8b\u5b50<\/strong><\/p>\n
<\/p>\n
\u7279\u6b8a\u5b57\u7b26<\/strong><\/div>\n\r\n\r\n\u7b26\u53f7\t\u542b\u4e49\t \u4e3e\u4f8b\r\n^\t\u5f00\u59cb\u6807\u8bb0\t \"^abc\"\u6ee1\u8db3\u7684\u4f8b\u5b50abc\u3001abcd\r\n^\t\u975e\uff08\u5728[]\u5185\uff09\t \"[^abc]\"\u6ee1\u8db3\u7684\u4f8b\u5b50\uff1addd\u3001mpd\r\n$\t\u7ed3\u675f\u6807\u8bb0 \t\u201dabc$\u201d\u6ee1\u8db3\u7684\u4f8b\u5b50abc\u3001mmabc\r\n.\t\u4efb\u610f\u5b57\u7b26 \t\"a.c\"\u6ee1\u8db3\u7684\u4f8b\u5b50abc\u3001fapcc\r\n\\< \u5339\u914d\u5355\u8bcd\u5f00\u59cb \t\"\\\t\u5339\u914d\u5355\u8bcd\u7ed3\u675f \t\"abc\\>\"\u6ee1\u8db3\u7684\u4f8b\u5b50abc\u3001pmrabc\r\n|\t\u6216\t \"AAA|BBB\"\u6ee1\u8db3\u7684\u4f8b\u5b50AAA\u3001BBBpp<\/pre>\n \u8303\u56f4<\/strong><\/div>\n\r\n\u7b26\u53f7\t\u542b\u4e49\t \u4e3e\u4f8b\r\n?\t\u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b260\u62161\u6b21\t \"abc?\"\u6ee1\u8db3\u7684\u4f8b\u5b50ab\u3001mabcd\r\n*\t\u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26\u22650\u6b21\t \"abc*\"\u6ee1\u8db3\u7684\u4f8b\u5b50abbb\u3001abcdk\r\n+\t\u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26\u22651\u6b21\t \"abc+\"\u6ee1\u8db3\u7684\u4f8b\u5b50abcd\u3001abcccdd\r\n{}\t{m}\u3001{m,n}\u3001{m,}\u3001{,n}\u5206\u522b\u4e3a\u5339\u914d\u524d\u4e00\u4e2a\u5b57\u7b26m\u6b21\u3001m\u5230n\u6b21\u3001\u2265m\u6b21\u3001\u2264n\u6b21 \"abc\\{3,5\\}\"\u6ee1\u8db3\u7684\u4f8b\u5b50abcccc\u3001abcccccc\r\n[]\t[]\u5185\u5982\u679c\u4e0d\u662f\u8303\u56f4\uff0c\u9009\u5176\u4e00\uff1b\u662f\u8303\u56f4\u7684\u8bdd\uff0c\u8303\u56f4\u5185\u9009\u5176\u4e00\t \"m[abc]p\"\u6ee1\u8db3\u7684\u4f8b\u5b50acpd\uff1bm[1-9]p\u6ee1\u8db3\u7684\u4f8b\u5b50m8pp\r\n()\t\u5c06\u5019\u9009\u7684\u6240\u6709\u5143\u7d20\u653e\u5728()\u5185\uff0c\u7528|\u9694\u5f00\t \"a(1|2|3)bc\"\u6ee1\u8db3\u7684\u4f8b\u5b50a1bc\u3001mba3bcd<\/pre>\n\u6ce8\u610f\uff1a{}\u5728\u90d1\u5219\u8868\u8fbe\u5f0f\u4e2d\u9700\u8981\u8f6c\u79fb\uff0c\u800c{}()\u4e0d\u9700\u8981\u3002 <\/p>\n
\u6ce8\u610f\u7406\u89e3{}\u8303\u56f4\u7684\u4f8b\u5b50\uff1a
\n<\/p>\n\u6807\u51c6\u5b57\u7b26\u7c7b<\/strong><\/div>\n\r\n\r\n\u5b57\u7b26\u7c7b\t\u91ca\u4e49\r\n[:alnum:]\t\u5b57\u6bcd\u548c\u6570\u5b57\uff0c\u4e0e[A-Za-z0-9]\u7b49\u4ef7\r\n[:word:]\t[:alnum:]\u52a0\u4e0a\u4e0b\u5212\u7ebf_\r\n[:alpa:]\t\u5b57\u6bcd\uff0c\u4e0e[A-Za-z]\u7b49\u4ef7\r\n[:digit:]\t\u6570\u5b57\uff0c\u4e0e[0-9]\u7b49\u4ef7\r\n[:xdigit:]\t\u5341\u516d\u8fdb\u5236\u5b57\u7b26\uff0c\u4e0e[0-9A-Fa-f\u7b49\u4ef7]\r\n[:blank:]\t\u7a7a\u683c\u548c\u5236\u8868\u7b26\r\n[:graph:]\t\u53ef\u89c1\u5b57\u7b26\uff0c\u9760\u626933~126\r\n[:lower:]\t\u5c0f\u5199\u5b57\u6bcd\r\n[:upper:]\t\u5927\u5199\u5b57\u6bcd\r\n[:print:]\t\u53ef\u6253\u5370\u5b57\u7b26\r\n[:space:]\t\u7a7a\u767d\u5b57\u7b26\uff0c\u7b49\u4ef7\u4e8e[\\t\\r\\n\\v\\f]\r\n[:punct:]\t\u6807\u70b9\u7b26\u53f7\r\n[:cntrl:]\tASCII\u63a7\u5236\u7801\uff0c\u5305\u62ec\u5b57\u7b260~31\u4ee5\u53ca127<\/pre>\n\n\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/www.linuxidc.com\/Linux\/2018-07\/153110.htm<\/a><\/p>\n