{"id":2803,"date":"2012-03-27T15:52:29","date_gmt":"2012-03-27T07:52:29","guid":{"rendered":"http:\/\/jpuyy.com\/?p=2803"},"modified":"2020-10-26T11:31:54","modified_gmt":"2020-10-26T03:31:54","slug":"grep-filter-files","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=2803","title":{"rendered":"grep\u8fdb\u884c\u7b5b\u9009"},"content":{"rendered":"<p>\u6392\u9664\u7a7a\u884c\u548c#\u5f00\u5934\u7684\u884c(grep -E \u6269\u5c55\u6b63\u5f52\u8868\u8fbe\u5f0f)<\/p>\n<pre>cat x.xx | grep -Ev \"^$|#\"<\/pre>\n<p>\u8fc7\u6ee4\u591a\u4e2a\u6761\u4ef6\uff0c\u6216\u7684\u5173\u7cfb<\/p>\n<pre class=\"p1\">ps aux | grep 'httpd\\|nginx'<\/pre>\n<pre class=\"p1\">ps aux | grep -E \"httpd|nginx\"<\/pre>\n<p>\u6392\u9664\u4ee5#\u5f00\u5934\u7684\u884c<\/p>\n<pre>cat x.xx | grep -v ^#<\/pre>\n<p>\u67e5\u770bfile1\u4e2d\u7a7a\u884c\u7684\u884c\u53f7<\/p>\n<pre>grep -n ^$ file1<\/pre>\n<p>\u9700\u8981\u4e25\u683c\u5339\u914d\uff0c\u5982\u7b5b\u9009abc\uff0c\u4e0d\u9700\u8981abcd,abcde\uff0c\u5219\u4f7f\u7528-w &#8211;word-regexp<\/p>\n<pre>grep -w \"abc\"<\/pre>\n<p>\u6216\u8005<\/p>\n<pre>grep \"\\&lt;abc\\&gt;\"<\/pre>\n<p>\u7ba1\u9053\u52a0grep -i\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d<\/p>\n<pre>lspci | grep -i ether\r\n 04:00.2 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111\/8168\/8411 PCI Express Gigabit Ethernet Controller (rev 0a)<\/pre>\n<p>\u76f4\u63a5\u53d6\u51fa\u5f53\u524d\u76ee\u5f55\u6587\u4ef6\u4e2d\u542b\u6709conf\u7684\u884c<\/p>\n<pre>grep -R 'conf' .<\/pre>\n<p>grep \u6253\u5370\u51fa\u524d\u9762before\uff0c\u540e\u9762after\uff0c\u5468\u8fb9around\u7684\u51e0\u884c<\/p>\n<pre>cat file | grep -A 1 aaa\r\ncat file | grep -B 1 aaa\r\ncat file | grep -C 1 aaa\r\n<\/pre>\n<p>\u9ad8\u4eae\u663e\u793a grep \u51fa\u6765\u7684\u5b57\u7b26<\/p>\n<pre>cat aaaa | grep --color aaaa<\/pre>\n<p>\u53bb\u6389\u6307\u5b9a\u7684\u51e0\u4e2a pattern<\/p>\n<pre>grep -v -e \"pattern1\" -e \"pattern2\"\r\ngrep -Ev \"pattern1|pattern2\"\r\n<\/pre>\n<p>\u5bf9\u8fc7\u6ee4\u7684\u7ed3\u679c\u8ba1\u6570(\u884c\u6570)<\/p>\n<pre>grep -c 'aaaa' filename<\/pre>\n<p>\u5f53\u524d\u76ee\u5f55\u627e\u5230\u6709\u67d0\u4e9b\u5b57\u7b26\u7684\u884c\u53ca\u6587\u4ef6<\/p>\n<pre>grep -rn 'bbs' .<\/pre>\n<p>\u5f53\u524d\u76ee\u5f55\u627e\u5230\u6709\u67d0\u4e9b\u5b57\u7b26\u7684\u6587\u4ef6<\/p>\n<pre>grep -rl 'bbs' .<\/pre>\n<p>\u53ea\u8f93\u51fa\u5339\u914d\u5230\u7684\u6587\u5b57<\/p>\n<p>\u4e0d\u8f93\u51fa\u6587\u4ef6\u540d<\/p>\n<pre>grep -h 'my_variable' \/data\/code\/*<\/pre>\n<p>\u4f8b\uff1a\u628a\u6240\u6709\u5b50\u57df\u540d\u6253\u5370\u51fa\u6765<\/p>\n<pre>cat domain.txt | grep -Eo '(\\w+.)+jpuyy.com'<\/pre>\n<p>grep \u6240\u6709 ip \u5730\u5740<\/p>\n<pre>grep -roE '([0-9]{1,3}\\.){3}[0-9]{1,3}' .<\/pre>\n<p>grep \u6240\u6709\u7684 ip \u7f51\u6bb5<\/p>\n<pre>grep -roE '([0-9]{1,3}\\.){3}[0-9]{1,3}\\\/[0-9]{1,2}' .<\/pre>\n<p>grep \u5305\u542b\u4e2d\u6587\u7684\u6587\u4ef6<\/p>\n<pre>grep -rl '[\\u4e00-\\u9fa5]'  .\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6392\u9664\u7a7a\u884c\u548c#\u5f00\u5934\u7684\u884c(grep -E \u6269\u5c55\u6b63\u5f52\u8868\u8fbe\u5f0f) cat x.xx | grep -Ev &#8220;^$|#&#8221; \u8fc7\u6ee4\u591a\u4e2a\u6761\u4ef6\uff0c\u6216\u7684\u5173\u7cfb ps aux | grep &#8216;httpd\\|nginx&#8217; ps aux | grep -E &#8220;httpd|nginx&#8221; \u6392\u9664\u4ee5#\u5f00\u5934\u7684\u884c cat x.xx | grep -v ^# \u67e5\u770bfile1\u4e2d\u7a7a\u884c\u7684\u884c\u53f7 grep -n ^$ file1 \u9700\u8981\u4e25\u683c\u5339\u914d\uff0c\u5982\u7b5b\u9009abc\uff0c\u4e0d\u9700\u8981abcd,abcde\uff0c\u5219\u4f7f\u7528-w &#8211;word-regexp grep -w &#8220;abc&#8221; \u6216\u8005 grep &#8220;\\&lt;abc\\&gt;&#8221; \u7ba1\u9053\u52a0grep -i\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d lspci | grep -i ether 04:00.2 Ethernet controller: Realtek Semiconductor Co., Ltd. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[],"class_list":["post-2803","post","type-post","status-publish","format-standard","hentry","category-regular-expression"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/2803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2803"}],"version-history":[{"count":22,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/2803\/revisions"}],"predecessor-version":[{"id":9153,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/2803\/revisions\/9153"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}