{"id":358,"date":"2024-12-03T14:50:42","date_gmt":"2024-12-03T06:50:42","guid":{"rendered":"https:\/\/znl.pub\/?p=358"},"modified":"2024-12-03T14:54:20","modified_gmt":"2024-12-03T06:54:20","slug":"%e6%98%be%e7%a4%ba%e6%96%87%e4%bb%b6%e4%b8%ad%e4%bb%8e%e6%9f%90%e4%b8%80%e8%a1%8c%e5%bc%80%e5%a7%8b%e4%b9%8b%e5%90%8e%e7%9a%84%e6%89%80%e6%9c%89%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/znl.pub\/?p=358","title":{"rendered":"\u663e\u793a\u6587\u4ef6\u4e2d\u4ece\u67d0\u4e00\u884c\u5f00\u59cb\u4e4b\u540e\u7684\u6240\u6709\u884c"},"content":{"rendered":"\n<p>\u5728 Linux \u4e2d\uff0c\u5982\u679c\u60f3\u8981\u663e\u793a\u4e00\u4e2a\u5927\u6587\u4ef6\u4e2d\u4ece\u67d0\u4e00\u884c\u5f00\u59cb\u4e4b\u540e\u7684\u6240\u6709\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u547d\u4ee4\u6765\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4f7f\u7528 <code>sed<\/code> \u547d\u4ee4<\/strong><\/h3>\n\n\n\n<p>sed \u662f\u4e00\u4e2a\u6d41\u7f16\u8f91\u5668\uff0c\u5b83\u53ef\u4ee5\u5728\u4e0d\u52a0\u8f7d\u6574\u4e2a\u6587\u4ef6\u5230\u5185\u5b58\u7684\u60c5\u51b5\u4e0b\u5904\u7406\u6587\u672c\u3002\u4f60\u53ef\u4ee5\u7528\u5b83\u6765\u6253\u5370\u51fa\u4ece\u7279\u5b9a\u884c\u53f7\u5f00\u59cb\u7684\u6240\u6709\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sed -n 'N,$p' filename<\/code><\/pre>\n\n\n\n<p>\u5c06 <code>N<\/code> \u66ff\u6362\u4e3a\u8981\u5f00\u59cb\u7684\u884c\u53f7\uff0c<code>filename<\/code> \u66ff\u6362\u4e3a\u5177\u4f53\u7684\u6587\u4ef6\u540d\u3002<code>-n<\/code> \u9009\u9879\u6291\u5236\u81ea\u52a8\u6253\u5370\u6a21\u5f0f\u7a7a\u95f4\u7684\u5185\u5bb9\uff0c<code>'N,$p'<\/code> \u6307\u5b9a\u4e86\u4e00\u4e2a\u5730\u5740\u8303\u56f4\uff0c\u8868\u793a\u4ece\u7b2c N \u884c\u5230\u6587\u4ef6\u7684\u6700\u540e\u4e00\u884c\uff08$\uff09\uff0c\u5e76\u6253\u5370\u8fd9\u4e9b\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u2299\u4f7f\u7528 tail \u547d\u4ee4<\/strong><\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u77e5\u9053\u8981\u4ece\u54ea\u4e00\u884c\u5f00\u59cb\uff0c\u4f46\u4e0d\u77e5\u9053\u8fd9\u4e00\u884c\u4e4b\u524d\u7684\u884c\u6570\uff0c\u53ef\u4ee5\u5148\u4f7f\u7528 <code>head<\/code> \u6216 <code>awk<\/code> \u627e\u5230\u8be5\u884c\u7684\u884c\u53f7\uff0c\u7136\u540e\u7ed3\u5408 <code>tail<\/code> \u6765\u8f93\u51fa\u4ece\u90a3\u4e00\u884c\u5f00\u59cb\u7684\u6240\u6709\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u4ece\u7b2c 1000 \u884c\u5f00\u59cb\u663e\u793a\u6240\u6709\u884c\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -n +1000 filename<\/code><\/pre>\n\n\n\n<p>+1000 \u8868\u793a\u4ece\u6587\u4ef6\u7684\u7b2c 1000 \u884c\u5f00\u59cb\u8bfb\u53d6\u76f4\u5230\u6587\u4ef6\u672b\u5c3e\u3002\u8fd9\u4e0e -1000 \u610f\u601d\u662f\u4e0d\u540c\u7684\uff0ctail -1000 \u6216\u8005 tail -n 1000 \u6216\u8005 tail -n -1000 \u8fd9\u4e09\u4e2a\u90fd\u662f\u7b49\u6548\u7684\uff0c\u90fd\u662f\u8868\u793a\u53d6\u6700\u540e1000\u884c\u6253\u5370\u51fa\u6765\u3002<strong>\u53e6\u5916\u9700\u8981\u6ce8\u610f\u4e0d\u652f\u6301 tail +1000 \u8fd9\u79cd\u5199\u6cd5\uff0c\u9700\u8981\u4f7f\u7528\u5b8c\u6574\u7684\u53c2\u6570\u5f62\u5f0f  tail -n +1000 \u3002<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4f7f\u7528 <code>awk<\/code> \u547d\u4ee4<\/strong><\/h3>\n\n\n\n<p><code>awk<\/code> \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u672c\u5904\u7406\u5de5\u5177\uff0c\u4e5f\u53ef\u4ee5\u7528\u6765\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>awk 'NR &gt;= N' filename<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc <code>NR<\/code> \u662f <code>awk<\/code> \u5185\u7f6e\u53d8\u91cf\uff0c\u4ee3\u8868\u5f53\u524d\u5904\u7406\u7684\u884c\u53f7\u3002<code>N<\/code> \u540c\u6837\u662f\u60f3\u8981\u5f00\u59cb\u7684\u884c\u53f7\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4f7f\u7528 <code>perl<\/code> \u547d\u4ee4<\/strong><\/h3>\n\n\n\n<p>Perl \u4e5f\u662f\u4e00\u79cd\u9009\u62e9\uff0c\u51e0\u4e4e\u6240\u6709linux\u90fd\u5185\u7f6ePerl\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>perl -ne 'print if $. &gt;= N' filename<\/code><\/pre>\n\n\n\n<p>$. \u662f Perl \u7684\u7279\u6b8a\u53d8\u91cf\uff0c\u8868\u793a\u5f53\u524d\u884c\u53f7\u3002\u4f20\u53c2 -n \u5f88\u91cd\u8981\uff0c\u8fd9\u4e2a\u9009\u9879\u544a\u8bc9 Perl \u5bf9\u8f93\u5165\u6587\u4ef6\u7684\u6bcf\u4e00\u884c\u90fd\u6267\u884c\u7ed9\u5b9a\u7684\u4ee3\u7801\u5757\uff0c\u5b83\u76f8\u5f53\u4e8e\u5728\u4f60\u7684\u4ee3\u7801\u5468\u56f4\u6dfb\u52a0\u4e86\u4e00\u4e2a\u9690\u5f0f\u7684\u5faa\u73af\uff0c\u7c7b\u4f3c\u4e8e while (&lt;&gt;) { \u2026 }\u3002\u8fd9\u4f7f\u5f97\u4f60\u53ef\u4ee5\u9010\u884c\u5904\u7406\u6587\u4ef6\uff0c\u800c\u4e0d\u9700\u8981\u663e\u5f0f\u5730\u5199\u4e00\u4e2a\u8bfb\u53d6\u6587\u4ef6\u7684\u5faa\u73af\u3002-e \u5c31\u662f\u547d\u4ee4\u884c\u4ee3\u7801\u6267\u884c\u4e86\u3002<\/p>\n\n\n\n<p>\u989d\u5916\u6269\u5c55\u4e00\u4e2a\u7279\u6b8a\u53d8\u91cf $_ \uff1a \u8868\u793a\u5f53\u524d\u884c\u7684\u5185\u5bb9\uff0c\u5728 Perl \u4e2d\uff0c$_ \u662f\u9ed8\u8ba4\u53d8\u91cf\uff0c\u5f53\u6ca1\u6709\u660e\u786e\u6307\u5b9a\u53d8\u91cf\u65f6\uff0c\u8bb8\u591a\u64cd\u4f5c\u90fd\u4f1a\u9ed8\u8ba4\u4f5c\u7528\u4e8e $_\u3002\u73b0\u5728\u6211\u4eec\u6362\u4e00\u79cd\u5199\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>perl -ne 'print \"$_\" if $. &gt;= N' filename<\/code><\/pre>\n\n\n\n<p>\u8fd9\u662f\u7b49\u6548\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Linux \u4e2d\uff0c\u5982\u679c\u60f3\u8981\u663e\u793a\u4e00\u4e2a\u5927\u6587\u4ef6\u4e2d\u4ece\u67d0\u4e00\u884c\u5f00\u59cb\u4e4b\u540e\u7684\u6240\u6709\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u547d\u4ee4\u6765\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u89c1\u7684&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-358","post","type-post","status-publish","format-standard","hentry","category-linux-use"],"_links":{"self":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=358"}],"version-history":[{"count":6,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/358\/revisions"}],"predecessor-version":[{"id":364,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/358\/revisions\/364"}],"wp:attachment":[{"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}