{"id":1233,"date":"2014-09-12T17:14:56","date_gmt":"2014-09-12T17:14:56","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=1233"},"modified":"2014-09-12T17:14:56","modified_gmt":"2014-09-12T17:14:56","slug":"linux%e6%8a%80%e5%b7%a7%e5%ad%a6%e4%b9%a02","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/1233.html","title":{"rendered":"Linux\u6280\u5de7\u5b66\u4e602"},"content":{"rendered":"<p>\u6700\u8fd1\u91cd\u6e29\u4e86awk\u548csed\u7b49\u7f16\u8f91\u547d\u4ee4\uff0c\u4e5f\u5e38\u7528Vim\u8fdb\u884c\u6587\u672c\u7684\u67e5\u770b\uff0c\u5b66\u5230\u4e86\u5f88\u591a\u7684\u5b9e\u7528\u6280\u5de7\uff0c\u8bb0\u5f55\u4e00\u4e0b\uff1a<\/p>\n<hr \/>\n<h4><strong>Vim<\/strong><strong>\u7684\u4e00\u4e9b\u6280\u5de7<\/strong><\/h4>\n<h5><strong>\u6d4f\u89c8\u4ee3\u7801<\/strong><strong> :E<\/strong><\/h5>\n<p>\u6ce8\u610f\uff0c\u662f\u5927\u5199\u3002\u4e4b\u540e\uff0c<strong style=\"line-height: 1.5;\">\u4f60\u53ef\u4ee5\u7528<\/strong><strong style=\"line-height: 1.5;\"> j, k <\/strong><strong style=\"line-height: 1.5;\">\u952e\u4e0a\u4e0b\u79fb\u52a8\uff0c\u7136\u540e\u56de\u8f66\uff0c\u8fdb\u5165\u4e00\u4e2a\u76ee\u5f55\uff0c\u6216\u662f\u627e\u5f00\u4e00\u4e2a\u6587\u4ef6<\/strong><span style=\"line-height: 1.5;\">\u3002\u4f60\u53ef\u4ee5\u770b\u5230\u4e0a\u9762\u6709\u4e00\u5806\u547d\u4ee4\uff1a<\/span><\/p>\n<ul>\n<li>\u3010 \u2013 \u3011 \u5230\u4e0a\u7ea7\u76ee\u5f55<\/li>\n<li>\u3010D\u3011\u5220\u9664\u6587\u4ef6\uff08\u5927\u5199\uff09<\/li>\n<li>\u3010R\u3011\u6539\u6587\u4ef6\u540d\uff08\u5927\u5199\uff09<\/li>\n<li>\u3010s\u3011\u5bf9\u6587\u4ef6\u6392\u5e8f\uff08\u5c0f\u5199\uff09<\/li>\n<li>\u3010x\u3011\u6267\u884c\u6587\u4ef6<\/li>\n<\/ul>\n<p>\u5f53\u7136\uff0c\u6253\u5f00\u7684\u6587\u4ef6\u4f1a\u628a\u73b0\u6709\u5df2\u6253\u5f00\u7684\u6587\u4ef6\u7ed9\u51b2\u6389\u2014\u2014\u4e5f\u5c31\u662f\u8bf4\u4f60\u53ea\u770b\u5230\u4e86\u4e00\u4e2a\u6587\u4ef6\u3002\u5982\u679c\u4f60\u8981\u6539\u53d8\u5f53\u524d\u6d4f\u89c8\u7684\u76ee\u5f55\uff0c\u6216\u662f\u67e5\u770b\u5f53\u524d\u6d4f\u89c8\u7684\u76ee\u5f55\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u548cshell\u4e00\u6837\u7684\u547d\u4ee4\uff1a<\/p>\n<p><strong>:cd &lt;dir&gt; <\/strong><strong>\u2013<\/strong> <strong>\u6539\u53d8\u5f53\u524d\u76ee\u5f55<\/strong><\/p>\n<p><strong>:pwd\u00a0 &#8211; <\/strong><strong>\u67e5\u770b\u5f53\u524d\u76ee\u5f55<\/strong><\/p>\n<h5><strong>\u7f13\u51b2\u533a<\/strong><strong>\u00a0\u00a0\u00a0\u00a0 :ls<\/strong><\/h5>\n<p>\u4e8e\u662f\uff0c\u5728\u4f60\u7684Vim\u4e0b\uff0c\u4f60\u4f1a\u770b\u5230\u5982\u4e0b\u754c\u9762\uff1a<\/p>\n<p><a href=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/09\/buffer_ls.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1234\" src=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/09\/buffer_ls.png\" alt=\"buffer_ls\" width=\"572\" height=\"174\" \/><\/a><\/p>\n<p>\u4f60\u53ef\u4ee5\u770b\u5230Vim\u6253\u5f00\u4e86\u56db\u4e2a\u6587\u4ef6\uff0c\u7f16\u53f7\u662f4\uff0c5\uff0c6\uff0c7\uff0c\u5982\u679c\u4f60\u8981\u5207\u6362\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u8fd9\u4e2a\u65f6\u5019\uff0c\u4f60\u4e0d\u8981\u6309\u56de\u8f66\uff08\u6309\u4e86\u4e5f\u6ca1\u4e8b\uff0c\u53ea\u4e0d\u8fc7\u6309\u4e86\u5c31\u770b\u4e0d\u5230:ls\u8f93\u51fa\u7684buffer\u5217\u8868\u4e86\uff09\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5207\u6362\u6587\u4ef6\uff08buffer\u540e\u9762\u76844\u8868\u793a\u5207\u52304\u53f7\u6587\u4ef6\u4e5f\u5c31\u662fsrc\/http\/ngx_http.c\uff09\uff1a<\/p>\n<p><strong>:buffer 4<\/strong><\/p>\n<p>\u6216\u662f\uff1a<\/p>\n<p><strong>:buffer src\/http\/ngx_http.c<\/strong><\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f60\u53ef\u4ee5\u50cf\u5728Shell\u4e2d\u8f93\u5165\u547d\u4ee4\u6309Tab\u952e\u8865\u5168\u4e00\u6837\u8865\u5168Vim\u7684\u547d\u4ee4\u3002<\/li>\n<li>\u4e5f\u53ef\u4ee5\u7528\u50cfgdb\u4e00\u6837\u7528\u6700\u524d\u9762\u7684\u51e0\u4e2a\u5b57\u7b26\uff0c\u53ea\u8981\u6ca1\u6709\u51b2\u7a81\u3002\u5982\uff1abuff<\/li>\n<\/ul>\n<p>\u4f60\u8fd8\u53ef\u4ee5\u52a8\u7528\u5982\u4e0b\u547d\u4ee4\uff0c\u5feb\u901f\u5207\u6362\uff1a<\/p>\n<p>:bnext\u00a0\u00a0\u00a0\u00a0\u00a0 \u7f29\u5199 :bn<br \/>\n:bprevious\u00a0\u00a0 \u7f29\u5199 :bp<br \/>\n:blast\u00a0 \u7f29\u5199 :bl<br \/>\n:bfirst \u7f29\u5199 :bf<\/p>\n<p>\u4e0a\u56fe\u4e2d\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u52305\u6709\u4e00\u4e2a%a\uff0c\u8fd9\u8868\u793a\u5f53\u524d\u6587\u4ef6\uff0c\u76f8\u5173\u7684\u6807\u8bb0\u5982\u4e0b\uff1a<\/p>\n<p>&#8211; \uff08\u975e\u6d3b\u52a8\u7684\u7f13\u51b2\u533a\uff09<br \/>\na \uff08\u5f53\u524d\u88ab\u6fc0\u6d3b\u7f13\u51b2\u533a\uff09<br \/>\nh \uff08\u9690\u85cf\u7684\u7f13\u51b2\u533a\uff09<br \/>\n% \uff08\u5f53\u524d\u7684\u7f13\u51b2\u533a\uff09<br \/>\n# \uff08\u4ea4\u6362\u7f13\u51b2\u533a\uff09<br \/>\n= \uff08\u53ea\u8bfb\u7f13\u51b2\u533a\uff09<br \/>\n+ \uff08\u5df2\u7ecf\u66f4\u6539\u7684\u7f13\u51b2\u533a\uff09<\/p>\n<h5><strong>\u7a97\u53e3\u5206\u5c4f\u6d4f\u89c8<\/strong><\/h5>\n<p>\u76f8\u4fe1\u4f60\u5728\u300a<a href=\"http:\/\/coolshell.cn\/articles\/1679.html\" target=\"_blank\">Vim\u7684\u7a97\u53e3\u5206\u5c4f<\/a>\u300b\u4e00\u6587\u4e2d\uff0c\u4f60\u5df2\u7ecf\u77e5\u9053\u4e86\u600e\u4e48\u62c6\u5206\u7a97\u53e3\u4e86\u3002\u5176\u5b9e\uff0c\u6211\u66f4\u591a\u7684\u4e0d\u662f\u7528\u62c6\u5206\u7a97\u53e3\u7684\u547d\u4ee4\uff0c\u800c\u662f\u7528\u6d4f\u89c8\u6587\u4ef6\u7684\u547d\u4ee4\u6765\u5206\u9694\u7a97\u53e3\u3002\u5982\uff1a<\/p>\n<p>\u628a\u5f53\u524d\u7a97\u53e3\u4e0a\u4e0b\u5206\u5c4f\uff0c\u5e76\u5728\u4e0b\u9762\u8fdb\u884c\u76ee\u5f55\u6d4f\u89c8\uff1a<\/p>\n<p><strong>:He\u00a0\u00a0 <\/strong><strong>\u5168\u79f0\u4e3a<\/strong><strong> :Hexplore\u00a0 <\/strong><strong>\uff08\u5728\u4e0b\u8fb9\u5206\u5c4f\u6d4f\u89c8\u76ee\u5f55\uff09<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u8981\u5728\u4e0a\u9762\uff0c\u4f60\u5c31\u5728 :He\u540e\u9762\u52a0\u4e2a !\uff0c<\/p>\n<p><strong>:He!\u00a0 <\/strong><strong>\uff08\u5728\u4e0a\u5206\u5c4f\u6d4f\u89c8\u76ee\u5f55\uff09<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u8981\u5de6\u53f3\u5206\u5c4f\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n<p><strong>:Ve <\/strong><strong>\u5168\u79f0\u4e3a<\/strong><strong> :Vexplore <\/strong><strong>\uff08\u5728\u5de6\u8fb9\u5206\u5c4f\u95f4\u6d4f\u89c8\u76ee\u5f55\uff0c\u8981\u5728\u53f3\u8fb9\u5219\u662f<\/strong><strong> :Ve!<\/strong><strong>\uff09<\/strong><\/p>\n<h5><strong>Tab<\/strong><strong>\u9875\u6d4f\u89c8<\/strong><\/h5>\n<p>\u5206\u5c4f\u53ef\u80fd\u4f1a\u8ba9\u4f60\u4e0d\u723d\uff0c\u4f60\u53ef\u80fd\u66f4\u559c\u6b22\u50cfChrome\u8fd9\u6837\u7684\u5206\u9875\u5f0f\u7684\u6d4f\u89c8\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n<p><strong>:Te\u00a0 <\/strong><strong>\u5168\u79f0\u662f<\/strong><strong> :Texplorer<\/strong><\/p>\n<p>\u4e0b\u56fe\u4e2d\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u6211\u7528Te\u547d\u4ee4\u6253\u5f00\u4e86\u4e09\u9875\uff0c\u5c31\u5728\u9876\u7aef\u6211\u4eec\u53ef\u4ee5\u53ef\u4ee5\u770b\u5230\u6709\u4e09\u9875\uff0c\u5176\u4e2d\u7b2c\u4e00\u9875Tab\u4e0a\u7684\u6570\u5b573\u8868\u793a\u90a3\u4e00\u9875\u67093\u4e2a\u6587\u4ef6\u3002<\/p>\n<p><strong>\u6211\u4eec\u8981\u5728\u591a\u4e2a<\/strong><strong>Tabe<\/strong><strong>\u9875\u4e2d\u5207\u6362\uff0c\u5728<\/strong><strong>normal<\/strong><strong>\u6a21\u5f0f\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u4e09\u4e2a\u6309\u952e\uff08\u6ce8\u610f\u6ca1\u6709\u5192\u53f7\uff09<\/strong>\uff1a<\/p>\n<p><strong>gt\u00a0\u00a0 <\/strong><strong>\u2013<\/strong> <strong>\u5230\u4e0b\u4e00\u4e2a\u9875<\/strong><\/p>\n<p><strong>gT\u00a0 &#8211; <\/strong><strong>\u5230\u524d\u4e00\u4e2a\u9875<\/strong><\/p>\n<p><strong>{i} gt\u00a0\u00a0 <\/strong><strong>\u2013<\/strong><strong> i<\/strong><strong>\u662f\u6570\u5b57\uff0c\u5230\u6307\u5b9a\u9875\uff0c\u6bd4\u5982\uff1a<\/strong><strong>5 gt <\/strong><strong>\u5c31\u662f\u5230\u7b2c<\/strong><strong>5<\/strong><strong>\u9875<\/strong><\/p>\n<p>\u4f60\u53ef\u4ee5\u4ee5\u4f7f\u7528 \u3010:tabm {n}\u3011\u6765\u5207\u6362Tab\u9875\u3002<\/p>\n<p>gvim\u5e94\u8be5\u662f\uff1aCtrl+PgDn \u548c Ctrl+PgUp \u6765\u5728\u5404\u4e2a\u9875\u4e2d\u5207\u6362\u3002<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u770b\u770b\u4f60\u73b0\u5728\u6253\u5f00\u7684\u7a97\u53e3\u548cTab\u7684\u60c5\u51b5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n<p><strong>:tabs<\/strong><\/p>\n<p>\u4e8e\u662f\u4f60\u53ef\u4ee5\u770b\u5230\uff1a<\/p>\n<p><a href=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/09\/Tab01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1235\" src=\"http:\/\/ixyzero.com\/blog\/wp-content\/uploads\/2014\/09\/Tab01.png\" alt=\"Tab01\" width=\"392\" height=\"175\" \/><\/a><\/p>\n<h5><strong>\u5176\u5b83\u7684\u4e00\u4e9b\u6280\u5de7<\/strong><\/h5>\n<h6><strong>\u5b57\u7b26\u76f8\u5173<\/strong><\/h6>\n<p>\u3010guu \u3011 \u2013 \u628a\u4e00\u884c\u7684\u6587\u5b57\u53d8\u6210\u5168\u5c0f\u5199\u3002\u6216\u662f\u3010Vu\u3011<\/p>\n<p>\u3010gUU\u3011 \u2013 \u628a\u4e00\u884c\u7684\u6587\u4ef6\u53d8\u6210\u5168\u5927\u5199\u3002\u6216\u662f\u3010VU\u3011<\/p>\n<p>\u6309\u3010v\u3011\u952e\u8fdb\u5165\u9009\u62e9\u6a21\u5f0f\uff0c\u7136\u540e\u79fb\u52a8\u5149\u6807\u9009\u62e9\u4f60\u8981\u7684\u6587\u672c\uff0c\u6309\u3010u\u3011\u8f6c\u5c0f\u5199\uff0c\u6309\u3010U\u3011\u8f6c\u5927\u5199<\/p>\n<p><strong>\u3010<\/strong><strong>ga<\/strong><strong>\u3011<\/strong> <strong>\u2013<\/strong><strong>\u00a0 <\/strong><strong>\u67e5\u770b\u5149\u6807\u5904\u5b57\u7b26\u7684<\/strong><strong>ascii<\/strong><strong>\u7801<\/strong><\/p>\n<p><strong>\u3010<\/strong><strong>g8<\/strong><strong>\u3011<\/strong> <strong>\u2013<\/strong> <strong>\u67e5\u770b\u5149\u6807\u5904\u5b57\u7b26\u7684<\/strong><strong>utf-8<\/strong><strong>\u7f16\u7801<\/strong><\/p>\n<p>\u3010gf\u3011\u00a0 &#8211; \u6253\u5f00\u5149\u6807\u5904\u6240\u6307\u7684\u6587\u4ef6 \uff08\u8fd9\u4e2a\u547d\u4ee4\u5728\u6253\u5230#include\u5934\u6587\u4ef6\u65f6\u633a\u597d\u7528\u7684\uff0c\u5f53\u7136\uff0c\u4ec5\u9650\u4e8e\u6709\u8def\u5f84\u7684\uff09<\/p>\n<p><strong>\u3010<\/strong><strong>*<\/strong><strong>\u3011\u6216\u3010<\/strong><strong>#<\/strong><strong>\u3011\u5728\u5f53\u524d\u6587\u4ef6\u4e2d\u641c\u7d22\u5f53\u524d\u5149\u6807\u7684\u5355\u8bcd<\/strong><\/p>\n<h6><strong>\u7f29\u8fdb\u76f8\u5173<\/strong><\/h6>\n<p>\u3010&gt;&gt;\u3011\u5411\u53f3\u7f29\u8fdb\u5f53\u524d\u884c \u3010&lt;&lt;\u3011\u5411\u5de6\u7f29\u8fdb\u5f53\u524d\u884c<\/p>\n<p>\u3010=\u3011\u00a0 &#8211; \u7f29\u8fdb\u5f53\u524d\u884c \uff08\u548c\u4e0a\u9762\u4e0d\u4e00\u6837\u7684\u662f\uff0c\u5b83\u4f1a\u5bf9\u9f50\u7f29\u8fdb\uff09<\/p>\n<p>\u3010=%\u3011 \u2013 \u628a\u5149\u6807\u4f4d\u7f6e\u79fb\u5230\u8bed\u53e5\u5757\u7684\u62ec\u53f7\u4e0a\uff0c\u7136\u540e\u6309=%\uff0c<strong>\u7f29\u8fdb\u6574\u4e2a\u8bed\u53e5\u5757<\/strong>\uff08%\u662f\u62ec\u53f7\u5339\u914d\uff09<\/p>\n<p>\u3010G=gg\u3011 \u6216\u662f \u3010gg=G\u3011\u00a0 &#8211; \u7f29\u8fdb\u6574\u4e2a\u6587\u4ef6\uff08G\u662f\u5230\u6587\u4ef6\u7ed3\u5c3e\uff0cgg\u662f\u5230\u6587\u4ef6\u5f00\u5934\uff09<\/p>\n<h6><strong>\u590d\u5236\u7c98\u8d34\u76f8\u5173<\/strong><\/h6>\n<p>\u6309\u3010v\u3011 \u952e\u8fdb\u5165\u9009\u62e9\u6a21\u5f0f\uff0c\u7136\u540e\u6309h,j,k,l\u79fb\u52a8\u5149\u6807\uff0c\u9009\u62e9\u6587\u672c\uff0c\u7136\u540e\u6309 \u3010y\u3011 \u8fdb\u884c\u590d\u5236\uff0c\u6309 \u3010p\u3011 \u8fdb\u884c\u7c98\u8d34\u3002<\/p>\n<p>\u3010dd\u3011\u526a\u5207\u4e00\u884c\uff08\u524d\u9762\u52a0\u4e2a\u6570\u5b57\u53ef\u4ee5\u526a\u5207n\u884c\uff09\uff0c\u3010p\u3011\u7c98\u8d34<\/p>\n<p>\u3010yy\u3011\u590d\u5236\u4e00\u884c\uff08\u524d\u9762\u52a0\u4e2a\u6570\u5b57\u53ef\u4ee5\u590d\u5236n\u884c\uff09\uff0c\u3010p\u3011\u7c98\u8d34<\/p>\n<h6><strong>\u5149\u6807\u79fb\u52a8\u76f8\u5173<\/strong><\/h6>\n<p>\u3010Ctrl + O\u3011\u5411\u540e\u56de\u9000\u4f60\u7684\u5149\u6807\u79fb\u52a8<\/p>\n<p>\u3010Ctrl + I \u3011\u5411\u524d\u8ffd\u8d76\u4f60\u7684\u5149\u6807\u79fb\u52a8<\/p>\n<p>\u8fd9\u4e24\u4e2a\u5feb\u6377\u952e\u5f88\u6709\u7528\uff0c\u53ef\u4ee5\u5728Tab\u9875\u548cWindows\u4e2d\u5411\u524d\u548c\u5411\u540etrace\u4f60\u7684\u5149\u6807\u952e\uff0c\u8fd9\u4e5f\u65b9\u4fbf\u4f60\u8df3\u8f6c\u5149\u6807\u3002<\/p>\n<h6><strong>\u8bfb\u53d6Shell\u547d\u4ee4\u76f8\u5173<\/strong><\/h6>\n<p>\u3010:r!date\u3011 \u63d2\u5165\u65e5\u671f<\/p>\n<p>\u4e0a\u9762\u8fd9\u4e2a\u547d\u4ee4\uff0c:r \u662f:read\u7684\u7f29\u5199\uff0c!\u662f\u8868\u660e\u8981\u8fd0\u884c\u4e00\u4e2ashell\u547d\u4ee4\uff0c\u610f\u601d\u662f\u6211\u8981\u628ashell\u547d\u4ee4\u7684\u8f93\u51fa\u8bfb\u5230vim\u91cc\u6765\u3002<\/p>\n<hr \/>\n<h4>\u8d85\u725b\u903c\/\u5b9e\u7528\u7684awk\u6280\u5de7<\/h4>\n<h6>\u4e00\u4e9b\u6ce8\u610f\u4e8b\u9879\/\u9884\u5907\u77e5\u8bc6\uff1a<\/h6>\n<ul>\n<li>\u5728\u5355\u5f15\u53f7\u4e2d\u7684\u88ab\u5927\u62ec\u53f7\u62ec\u7740\u7684\u5c31\u662fawk\u7684\u8bed\u53e5\uff0c\u6ce8\u610f\uff0c\u5176\u53ea\u80fd\u88ab\u5355\u5f15\u53f7\u5305\u542b\u3002<\/li>\n<li>\u5176\u4e2d\u7684$1..$n\u8868\u793a\u7b2c\u51e0\u5217\u3002\u6ce8\uff1a$0\u8868\u793a\u6574\u4e2a\u884c\u3002<\/li>\n<\/ul>\n<p>\u5728\u8fdb\u884c\u4e00\u4e9b\u7a0d\u5fae\u590d\u6742\u70b9\u7684awk\u4f7f\u7528\u65f6\uff0c\u7ecf\u5e38\u4f1a\u78b0\u5230END\u5173\u952e\u5b57\u3002END\u7684\u610f\u601d\u662f\u201c\u5904\u7406\u5b8c\u6240\u6709\u7684\u884c\u7684\u6807\u8bc6\u201d\uff0c\u5373\u7136\u8bf4\u5230\u4e86END\u5c31\u6709\u5fc5\u8981\u4ecb\u7ecd\u4e00\u4e0bBEGIN\uff0c\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u610f\u5473\u7740\u6267\u884c\u524d\u548c\u6267\u884c\u540e\u7684\u610f\u601d\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>BEGIN{ \u8fd9\u91cc\u9762\u653e\u7684\u662f\u6267\u884c\u524d\u7684\u8bed\u53e5 }<\/li>\n<li>END {\u8fd9\u91cc\u9762\u653e\u7684\u662f\u5904\u7406\u5b8c\u6240\u6709\u7684\u884c\u540e\u8981\u6267\u884c\u7684\u8bed\u53e5 }<\/li>\n<li>{\u8fd9\u91cc\u9762\u653e\u7684\u662f\u5904\u7406\u6bcf\u4e00\u884c\u65f6\u8981\u6267\u884c\u7684\u8bed\u53e5}<\/li>\n<\/ul>\n<h6>\u7528awk\u6765\u8fc7\u6ee4\u8bb0\u5f55\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">$ awk '$3==0 &amp;&amp; $6==\"LISTEN\" ' netstat.txt<\/pre>\n<p>\u5176\u4e2d\u7684\u201c==\u201d\u4e3a\u6bd4\u8f83\u8fd0\u7b97\u7b26\u3002\u5176\u4ed6\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff1a!=, &gt;, &lt;, &gt;=, &lt;=<\/p>\n<pre class=\"lang:default decode:true\">$ awk ' $3&gt;0 {print $0}' netstat.txt\nProto Recv-Q Send-Q Local-Address Foreign-Address State\ntcp 0 4166 coolshell.cn:80 61.148.242.38:30901 ESTABLISHED\ntcp 0 1 coolshell.cn:80 124.152.181.209:26825 FIN_WAIT1\ntcp 0 1 coolshell.cn:80 208.115.113.92:50601 LAST_ACK<\/pre>\n<h6>\u5982\u679c\u6211\u4eec\u9700\u8981\u8868\u5934\u7684\u8bdd\uff0c\u6211\u4eec\u53ef\u4ee5\u5f15\u5165\u5185\u5efa\u53d8\u91cfNR\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">$ awk '$3==0 &amp;&amp; $6==\"LISTEN\" || NR==1 ' netstat.txt\nProto Recv-Q Send-Q Local-Address Foreign-Address State\ntcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN\ntcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN<\/pre>\n<h6>awk\u7684\u5185\u5efa\u53d8\u91cf\uff1a<\/h6>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"4\">\n<tbody>\n<tr>\n<td bgcolor=\"#ffffff\">$0<\/td>\n<td bgcolor=\"#ffffff\">\u5f53\u524d\u8bb0\u5f55\uff08\u8fd9\u4e2a\u53d8\u91cf\u4e2d\u5b58\u653e\u7740\u6574\u4e2a\u884c\u7684\u5185\u5bb9\uff09<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">$1~$n<\/td>\n<td bgcolor=\"#ffffff\">\u5f53\u524d\u8bb0\u5f55\u7684\u7b2cn\u4e2a\u5b57\u6bb5\uff0c\u5b57\u6bb5\u95f4\u7531FS\u5206\u9694<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">FS<\/td>\n<td bgcolor=\"#ffffff\">\u8f93\u5165\u5b57\u6bb5\u5206\u9694\u7b26 \u9ed8\u8ba4\u662f\u7a7a\u683c\u6216Tab<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">NF<\/td>\n<td bgcolor=\"#ffffff\">\u5f53\u524d\u8bb0\u5f55\u4e2d\u7684\u5b57\u6bb5\u4e2a\u6570\uff0c\u5c31\u662f\u6709\u591a\u5c11\u5217<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">NR<\/td>\n<td bgcolor=\"#ffffff\">\u5df2\u7ecf\u8bfb\u51fa\u7684\u8bb0\u5f55\u6570\uff0c\u5c31\u662f\u884c\u53f7\uff0c\u4ece1\u5f00\u59cb\uff0c\u5982\u679c\u6709\u591a\u4e2a\u6587\u4ef6\u8bdd\uff0c\u8fd9\u4e2a\u503c\u4e5f\u662f\u4e0d\u65ad\u7d2f\u52a0\u4e2d\u3002<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">FNR<\/td>\n<td bgcolor=\"#ffffff\">\u5f53\u524d\u8bb0\u5f55\u6570\uff0c\u4e0eNR\u4e0d\u540c\u7684\u662f\uff0c\u8fd9\u4e2a\u503c\u4f1a\u662f\u5404\u4e2a\u6587\u4ef6\u81ea\u5df1\u7684\u884c\u53f7<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">RS<\/td>\n<td bgcolor=\"#ffffff\">\u8f93\u5165\u7684\u8bb0\u5f55\u5206\u9694\u7b26\uff0c \u9ed8\u8ba4\u4e3a\u6362\u884c\u7b26<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">OFS<\/td>\n<td bgcolor=\"#ffffff\">\u8f93\u51fa\u5b57\u6bb5\u5206\u9694\u7b26\uff0c \u9ed8\u8ba4\u4e5f\u662f\u7a7a\u683c<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">ORS<\/td>\n<td bgcolor=\"#ffffff\">\u8f93\u51fa\u7684\u8bb0\u5f55\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u4e3a\u6362\u884c\u7b26<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#ffffff\">FILENAME<\/td>\n<td bgcolor=\"#ffffff\">\u5f53\u524d\u8f93\u5165\u6587\u4ef6\u7684\u540d\u5b57<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<div id=\"crayon-541bd2baae642043582941-1\" class=\"crayon-line\">\n<pre class=\"lang:default decode:true\"># awk\u8c03\u7528\u5916\u90e8\u53d8\u91cf\u662f\u9700\u8981\u7528\u201c\u5355\u5f15\u53f7\u201d\u62ec\u8d77\u6765\u3002\u6216\u8005\u5728\u524d\u9762\u7528 -v \u9009\u9879\u6dfb\u52a0\u8fd9\u4e2a\u5916\u90e8\u53d8\u91cf\u3002\n#\u00a0awk '{if($1&gt;='$n') print $2}' file<\/pre>\n<\/div>\n<h6>\u6298\u5206\u6587\u4ef6<\/h6>\n<p>awk\u62c6\u5206\u6587\u4ef6\u5f88\u7b80\u5355\uff0c\u4f7f\u7528\u91cd\u5b9a\u5411\u5c31\u597d\u4e86\u3002\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u662f\u6309\u7b2c6\u4f8b\u5206\u9694\u6587\u4ef6\uff0c\u76f8\u5f53\u7684\u7b80\u5355\uff08\u5176\u4e2d\u7684NR!=1\u8868\u793a\u4e0d\u5904\u7406\u8868\u5934\uff09\u3002<\/p>\n<pre class=\"lang:default decode:true\">$ awk 'NR!=1{print &gt; $6}' netstat.txt<\/pre>\n<h6>\u7edf\u8ba1<\/h6>\n<p>\u4e0b\u9762\u7684\u547d\u4ee4\u8ba1\u7b97\u6240\u6709\u7684C\u6587\u4ef6\uff0cCPP\u6587\u4ef6\u548cH\u6587\u4ef6\u7684\u6587\u4ef6\u5927\u5c0f\u603b\u548c\u3002<\/p>\n<pre class=\"lang:default decode:true \">$ ls -l *.cpp *.c *.h | awk '{sum+=$5} END {print sum}'\n2511401<\/pre>\n<hr \/>\n<div><span style=\"color: #ff0000;\"><strong>Bash\u4e2d\u7684for\u5faa\u73af<\/strong><\/span>\uff08\u5982\u4f55\u4eceLinux\u539f\u751f\u7cfb\u7edf\u4e2d\u627e\u5230\u89e3\u51b3\u95ee\u9898\u7684\u63d0\u793a\uff1f\u76f4\u63a5\u6267\u884c\u547d\u4ee4\uff1a<strong>man bash<\/strong>\u5373\u53ef\u67e5\u770b\u3002\uff09<\/div>\n<div>\u811a\u672cexample.sh<\/div>\n<div>\n<div>\n<pre class=\"lang:default decode:true\">#!\/bin\/sh\nfor i in {1..100}; do\n    echo $i\ndone<\/pre>\n<\/div>\n<div>\u5982\u679c\u7b80\u5355\u6267\u884c\uff1a.\/example.sh \uff0c\u8f93\u51fa\u4e3a\uff1a<\/div>\n<div>{1..100}<\/div>\n<div><\/div>\n<div>\u4f46\u662f\u5982\u679c\u5c06\u7b2c\u4e00\u884c\u4fee\u6539\u4e3a#!\/bin\/bash \u5219\u53ef\u4ee5\u6309\u7167\u81ea\u5df1\u7684\u9884\u671f\u8f93\u51fa1-100\u7684\u5faa\u73af\uff1b\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\uff1abash example.sh\u6765\u8fbe\u5230\u540c\u6837\u7684\u76ee\u7684\u3002\u5509\uff0c\u9009\u62e9\u7684shell\u4e0d\u540c\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u4e5f\u4e0d\u540c\uff0c\u9700\u8981\u6ce8\u610f\u554a\uff01<\/div>\n<div>\u5bf9\u4e8eshell\u7f16\u7a0b\u4e2d\u7684\u5404\u79cd\u5751\uff0c\u771f\u7684\u662f\u8e29\u4e5f\u8e29\u4e0d\u5b8co(\u256f\u25a1\u2570)o<\/p>\n<hr \/>\n<\/div>\n<\/div>\n<h6>#\u751f\u6210\u590d\u6742\u5bc6\u7801<\/h6>\n<div>\n<pre class=\"lang:default decode:true\">openssl rand 20 -base64\nuuidgen<\/pre>\n<\/div>\n<h6>#Vim<\/h6>\n<div>\n<pre class=\"lang:default decode:true\">:w !sudo tee %<\/pre>\n<\/div>\n<h6>#\u7edf\u8ba1\u67d0\u4e00\u6587\u4ef6\u5939\uff08\u5305\u62ec\u5b50\u6587\u4ef6\u5939\u4e0b\uff09\u7684\u6587\u4ef6\u4e2a\u6570<\/h6>\n<div>\n<pre class=\"lang:default decode:true \">#\u65b9\u6cd5\u4e00\uff1a\nls -lR | grep \"^-\" | wc -l\n#\u65b9\u6cd5\u4e8c\uff1a\nfind .\/ -type f | wc -l<\/pre>\n<h6>\u53bb\u6389\u6587\u4ef6\u4e2d\u7684utf-8 BOM\u5934<\/h6>\n<pre class=\"lang:default decode:true \">awk '{if(NR==1)sub(\/^xefxbbxbf\/,\"\") print}' input.txt &gt; output.txt<\/pre>\n<h6>\u6bd4\u8f83\u4e24\u4e2a\u6587\u4ef6\uff0c\u627e\u51fa\u57281.txt\u4e2d\u4e0d\u57282.txt\u4e2d\u7684\u5185\u5bb9<\/h6>\n<pre class=\"lang:default decode:true \">awk 'NR==FNR{a[$0]++}NR&gt;FNR{if(a[$0]==0) print}' 1.txt 2.txt &gt; diff.txt<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h6>\u5b66\u4e60\u5730\u5740\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/coolshell.cn\/articles\/11312.html\" target=\"_blank\">\u65e0\u63d2\u4ef6Vim\u7f16\u7a0b\u6280\u5de7 | \u9177 \u58f3 &#8211; CoolShell.cn<\/a><\/li>\n<li><a href=\"http:\/\/coolshell.cn\/articles\/9070.html\" target=\"_blank\">AWK \u7b80\u660e\u6559\u7a0b | \u9177 \u58f3 &#8211; CoolShell.cn<\/a><\/li>\n<li>\n<div><a href=\"http:\/\/see.xidian.edu.cn\/cpp\/shell\/\" target=\"_blank\">Linux Shell\u811a\u672c\u6559\u7a0b\uff1a30\u5206\u949f\u73a9\u8f6cShell\u811a\u672c\u7f16\u7a0b<\/a><\/div>\n<\/li>\n<li>\n<div><a href=\"http:\/\/www.cnblogs.com\/chengmo\/archive\/2010\/10\/26\/1861809.html\" target=\"_blank\">linux shell man\u547d\u4ee4\u8be6\u7ec6\u4ecb\u7ecd-\u5feb\u6377\u83b7\u5f97\u5e2e\u52a9\u4fe1\u606f(2)<\/a><\/div>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u91cd\u6e29\u4e86awk\u548csed\u7b49\u7f16\u8f91\u547d\u4ee4\uff0c\u4e5f\u5e38\u7528Vim\u8fdb\u884c\u6587\u672c\u7684\u67e5\u770b\uff0c\u5b66\u5230\u4e86\u5f88\u591a\u7684\u5b9e\u7528\u6280\u5de7\uff0c\u8bb0\u5f55\u4e00\u4e0b\uff1a Vim\u7684\u4e00\u4e9b [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,12],"tags":[74,43],"class_list":["post-1233","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-tools","tag-awk","tag-vim"],"views":6083,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=1233"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1233\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=1233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=1233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=1233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}