{"id":282589,"date":"2023-09-11T20:05:25","date_gmt":"2023-09-11T12:05:25","guid":{"rendered":"https:\/\/lrxjmw.cn\/lsjsagcjyx.html"},"modified":"2023-09-11T20:05:25","modified_gmt":"2023-09-11T12:05:25","slug":"lsjsagcjyx","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lsjsagcjyx.html","title":{"rendered":"linux sed awk grep Linux\u795e\u6280\uff1aSed\u3001Awk\u3001Grep\u8d85\u7ea7\u82f1\u96c4"},"content":{"rendered":"
\u5c0f\u7f16\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e0bLinux<\/a>\u547d\u4ee4<\/a>\u884c\u4e2d\u7684\u4e09\u4f4d\u8d85\u7ea7\u82f1\u96c4\uff1aSed\u3001Awk\u548cGrep\u3002\u8fd9\u4e09\u4e2a\u547d\u4ee4\u662fLinux\u7cfb\u7edf<\/a>\u4e2d\u975e\u5e38\u5f3a\u5927\u4e14\u5e38\u7528\u7684\u5de5\u5177\uff0c\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u6587\u672c\u5904\u7406\u548c\u6570\u636e\u5206\u6790\u65b9\u9762\u4e8b\u534a\u529f\u500d\u3002\u63a5\u4e0b\u6765\uff0c\u5c0f\u7f16\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5b83\u4eec\u7684\u529f\u80fd\u548c\u7528\u6cd5\uff0c\u8ba9\u4f60\u5728\u4f7f\u7528Linux\u547d\u4ee4\u884c\u65f6\u6e38\u5203\u6709\u4f59\u3002<\/p>\n 1. Sed\uff08Stream Editor\uff09-\u6d41\u5f0f\u7f16\u8f91\u5668<\/p>\n Sed\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u672c\u5904\u7406\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5bf9\u6587\u672c\u8fdb\u884c\u4fee\u6539\u3001\u66ff\u6362\u3001\u5220\u9664\u7b49\u64cd\u4f5c\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Sed\u547d\u4ee4\u8f7b\u677e\u5730\u5c06\u4e00\u7bc7\u6587\u7ae0\u4e2d\u7684\u6240\u6709\"Linux\"\u66ff\u6362\u4e3a\"GNU\/Linux\"\uff0c\u6216\u8005\u5220\u9664\u6240\u6709\u7a7a\u884c\u3002\u53ea\u9700\u8981\u7b80\u5355\u7684\u547d\u4ee4\u5c31\u80fd\u5b8c\u6210\u590d\u6742\u7684\u4efb\u52a1\u3002<\/p>\n 2. Awk -\u5f3a\u5927\u7684\u6587\u672c\u5206\u6790\u5668<\/p>\n Awk\u662f\u4e00\u79cd\u7075\u6d3b\u800c\u5f3a\u5927\u7684\u6587\u672c\u5206\u6790\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u6839\u636e\u6307\u5b9a\u7684\u89c4\u5219\u4ece\u6587\u672c\u4e2d\u63d0\u53d6\u51fa\u9700\u8981\u7684\u4fe1\u606f\uff0c\u5e76\u8fdb\u884c\u5904\u7406\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Awk\u547d\u4ee4\u8f7b\u677e\u5730\u4ece\u65e5\u5fd7\u6587\u4ef6\u4e2d\u63d0\u53d6\u7279\u5b9a\u65f6\u95f4\u6bb5\u5185\u7684\u6570\u636e\uff0c\u5e76\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u3002Awk\u8fd8\u652f\u6301\u81ea\u5b9a\u4e49\u51fd\u6570\u548c\u53d8\u91cf\uff0c\u4f7f\u5f97\u5b83\u66f4\u52a0\u7075\u6d3b\u6613\u7528\u3002<\/p>\n 3. Grep -\u5f3a\u5927\u7684\u6587\u672c\u641c\u7d22\u5de5\u5177<\/p>\n Grep\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u672c\u641c\u7d22\u5de5\u5177linux\u7cfb\u7edf\u754c\u9762\uff0c\u5b83\u53ef\u4ee5\u5728\u6587\u4ef6\u6216\u8005\u6587\u672c\u6d41\u4e2d\u67e5\u627e\u6307\u5b9a\u7684\u6a21\u5f0f\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Grep\u547d\u4ee4\u5feb\u901f\u5730\u67e5\u627e\u5305\u542b\u7279\u5b9a\u5173\u952e\u8bcd\u7684\u6587\u4ef6linux sed awk grep<\/strong>\uff0c\u6216\u8005\u4ece\u5927\u91cf\u6570\u636e\u4e2d\u63d0\u53d6\u51fa\u9700\u8981\u7684\u4fe1\u606f\u3002Grep\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8ba9\u4f60\u7684\u641c\u7d22\u66f4\u52a0\u7075\u6d3b\u548c\u51c6\u786e\u3002<\/p>\n 4. Sed\u3001Awk\u548cGrep\u7684\u7ec4\u5408\u62f3<\/p>\n <\/p>\n \u5f53\u8fd9\u4e09\u4e2a\u547d\u4ee4\u7ed3\u5408\u5728\u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u5b83\u4eec\u7684\u5a01\u529b\u5c06\u66f4\u52a0\u5f3a\u5927\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Grep\u547d\u4ee4\u7b5b\u9009\u51fa\u9700\u8981\u5904\u7406\u7684\u6570\u636e\u96c6\uff0c\u7136\u540e\u4f7f\u7528Awk\u547d\u4ee4\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\uff0c\u6700\u540e\u518d\u4f7f\u7528Sed\u547d\u4ee4\u5bf9\u7ed3\u679c\u8fdb\u884c\u4fee\u9970\u548c\u4fee\u6539\u3002\u8fd9\u6837\u7684\u7ec4\u5408\u62f3\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5feb\u901f\u5730\u5904\u7406\u5927\u91cf\u6570\u636e\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n 5.\u5b9e\u4f8b\u6f14\u793a<\/p>\n \u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u5b83\u4eec\u7684\u7528\u6cd5\uff0c\u4e0b\u9762\u4e3e\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u4f8b\u6f14\u793a\uff1a<\/p>\n \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6access.log\uff0c\u91cc\u9762\u8bb0\u5f55\u4e86\u7f51\u7ad9\u8bbf\u95ee\u65e5\u5fd7\u3002\u6211\u4eec\u60f3\u8981\u7edf\u8ba1\u67d0\u4e2a\u65f6\u95f4\u6bb5\u5185\u8bbf\u95ee\u6b21\u6570\u6700\u591a\u7684IP\u5730\u5740\u3002<\/p>\n \u9996\u5148\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Grep\u547d\u4ee4\u7b5b\u9009\u51fa\u76ee\u6807\u65f6\u95f4\u6bb5\u5185\u7684\u65e5\u5fd7\uff1a<\/p>\n \n \u7136\u540e\u5d4c\u5165\u5f0flinux\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Awk\u547d\u4ee4\u63d0\u53d6\u51faIP\u5730\u5740\uff0c\u5e76\u8fdb\u884c\u7edf\u8ba1\uff1a<\/p>\n \n \u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Sed\u547d\u4ee4\u5bf9\u7ed3\u679c\u8fdb\u884c\u4fee\u9970\uff1a<\/p>\n \n \u901a\u8fc7\u8fd9\u4e2a\u7b80\u5355\u7684\u5b9e\u4f8b\uff0c\u76f8\u4fe1\u4f60\u5df2\u7ecf\u5bf9Sed\u3001Awk\u548cGrep\u6709\u4e86\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u3002<\/p>\n 6.\u603b\u7ed3<\/p>\n Sed\u3001Awk\u548cGrep\u662fLinux\u547d\u4ee4\u884c\u4e2d\u975e\u5e38\u5f3a\u5927\u4e14\u5e38\u7528\u7684\u5de5\u5177\u3002\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u6587\u672c\u5904\u7406\u548c\u6570\u636e\u5206\u6790\u65b9\u9762\u4e8b\u534a\u529f\u500d\u3002\u719f\u7ec3\u638c\u63e1\u5b83\u4eec\u7684\u7528\u6cd5linux sed awk grep<\/strong>\uff0c\u5c06\u6781\u5927\u5730\u63d0\u9ad8\u6211\u4eec\u7684\u5de5\u4f5c\u6548\u7387\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u8005\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u968f\u65f6\u7559\u8a00\uff0c\u5c0f\u7f16\u4f1a\u5c3d\u5feb\u56de\u590d\u54e6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":" \u8fd9\u4e09\u4e2a\u547d\u4ee4\u662fLinux\u7cfb\u7edf\u4e2d\u975e\u5e38\u5f3a\u5927\u4e14\u5e38\u7528\u7684\u5de5\u5177\uff0c\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u6587\u672c\u5904\u7406\u548c\u6570\u636e\u5206\u6790\u65b9\u9762\u4e8b\u534a\u529f\u500d\u3002Awk\u8fd8\u652f\u6301\u81ea\u5b9a\u4e49\u51fd\u6570\u548c\u53d8\u91cf\uff0c\u4f7f\u5f97\u5b83\u66f4\u52a0\u7075\u6d3b\u6613\u7528\u3002Grep\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u672c\u641c\u7d22\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5728\u6587\u4ef6\u6216\u8005\u6587\u672c\u6d41\u4e2d\u67e5\u627e\u6307\u5b9a\u7684\u6a21\u5f0f\u3002Grep\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8ba9\u4f60\u7684\u641c\u7d22\u66f4\u52a0\u7075\u6d3b\u548c\u51c6\u786e\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6access.log\uff0c\u91cc\u9762\u8bb0\u5f55\u4e86\u7f51\u7ad9\u8bbf\u95ee\u65e5\u5fd7\u3002<\/p>\n","protected":false},"author":1,"featured_media":282590,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-282589","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=282589"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282589\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/282590"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=282589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=282589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=282589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\ngrep "2023-09-10 12:00:00" access.log | grep "GET \/"\n<\/pre>\n<\/p>\n
\nawk '{print $1}'| sort | uniq -c| sort -rn\n<\/pre>\n<\/p>\n
\nsed 's\/^*\/\/;s\/\/:\/'\n<\/pre>\n<\/p>\n