{"id":1984,"date":"2015-03-07T21:33:52","date_gmt":"2015-03-07T13:33:52","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=1984"},"modified":"2015-03-07T21:33:52","modified_gmt":"2015-03-07T13:33:52","slug":"awk%e5%ad%a6%e4%b9%a0_5","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/1984.html","title":{"rendered":"Awk\u5b66\u4e60_5"},"content":{"rendered":"<h5>1.\u6253\u5370\u6307\u5b9a\u884c<\/h5>\n<p>Q:\u5982\u4f55\u7528awk\u6253\u5370\u67d0\u4e00\u6587\u4ef6\u7684\u7b2c3\u884c\u4e4b\u540e\u7684\u6240\u6709\u884c\uff1f<\/p>\n<p>A:\u53ef\u4ee5\u5229\u7528awk\u7684NR\u53d8\u91cf\u3002<\/p>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<p><a href=\"http:\/\/search.aol.com\/aol\/search?q=awk+print+all+but+the+first+three+lines\" target=\"_blank\">http:\/\/search.aol.com\/aol\/search?q=awk+print+all+but+the+first+three+lines<\/a><\/p>\n<h6>\u7ed3\u8bba\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">$ awk 'NR&gt;10' mem_cpu_usage.txt | wc -l\n753\n\n$ wc -l mem_cpu_usage.txt\n763 mem_cpu_usage.txt<\/pre>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<p><a href=\"http:\/\/askubuntu.com\/questions\/475694\/awk-command-to-print-all-the-lines-except-the-last-three-lines\" target=\"_blank\">http:\/\/askubuntu.com\/questions\/475694\/awk-command-to-print-all-the-lines-except-the-last-three-lines <\/a>#\u6709\u6027\u80fd\u6bd4\u8f83\u7edf\u8ba1\uff01<\/p>\n<h5>2.\u6253\u5370\u6307\u5b9a\u5217<\/h5>\n<p>Q:\u5982\u4f55\u7528awk\u6253\u5370\u67d0\u4e00\u6587\u4ef6\u7684\u7b2c3\u5217\u4e4b\u540e\u7684\u6240\u6709\u5217\uff1f<\/p>\n<p>A:\u5229\u7528awk\u8fdb\u884c\u7f16\u7a0b\u3002<\/p>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<p><a href=\"http:\/\/search.aol.com\/aol\/search?q=awk+print+all+but+the+first+three+columns\" target=\"_blank\">http:\/\/search.aol.com\/aol\/search?q=awk+print+all+but+the+first+three+columns<\/a><\/p>\n<h6>\u7ed3\u8bba\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">awk '{for(i=1;i&lt;4;i++) $i=\"\";print}' file\nawk '{$1=$2=$3=\"\";print}' file\nawk '{ $1=\"\"; $2=\"\"; $3=\"\"; print $0 }' file<\/pre>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/2961635\/using-awk-to-print-all-columns-from-the-nth-to-the-last\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/2961635\/using-awk-to-print-all-columns-from-the-nth-to-the-last<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/2626274\/print-all-but-the-first-three-columns\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/2626274\/print-all-but-the-first-three-columns<\/a><\/li>\n<li><a href=\"http:\/\/superuser.com\/questions\/211406\/awk-print-from-the-third-field-until-end-of-line-each-word-with-one-space\" target=\"_blank\">http:\/\/superuser.com\/questions\/211406\/awk-print-from-the-third-field-until-end-of-line-each-word-with-one-space<\/a><\/li>\n<\/ul>\n<h5>3.\u53bb\u91cd<\/h5>\n<pre class=\"lang:default decode:true \">awk '{dict[$2]++}; END{for(i in dict) print dict[i]\"\\t\"i}'    #count\n\nawk '{dict[$2]=dict[$2]+$1}; END{for(i in dict) print dict[i]\"\\t\"i}'\t#sum\n\nawk '{type[\"all\"]+=$3; type[$2]+=$3} END{for(i in type) print i\"\\t\"type[i]}'  #sum too\n\nawk '{dict[$1]++}; END{for(i in dict) print dict[i]\"\\t\"i}'  #count\n\nls -lt web_log\/ | awk '$5!=5343{print $5}' | awk '{dict[$1]++}; END{for(i in dict) print dict[i]\"\\t\"i}'\nfind web_log\/ -iname \"*.txt\" | xargs ls -l | awk '$5!=5343{print $5}' | awk '{dict[$1]++}; END{for(i in dict) print dict[i]\"\\t\"i}'\nfind web_log\/ -iname \"*.txt\" | xargs ls -l | awk '$5!=5343{print $5}' | awk '{dict[$1]++; dict[\"all\"]++}; END{for(i in dict) print dict[i]\"\\t\"i}'\n\nawk '$5==5343' | wc -l<\/pre>\n<h5>4.\u4e00\u4e9b\u5e94\u7528<\/h5>\n<pre class=\"lang:default decode:true \">awk '$1 !~ \/lo\/ &amp;&amp; NR!=1 &amp;&amp; NR!=2' \/proc\/net\/dev | awk 'BEGIN{max=0} {if($2+0 &gt; max+0) max=$2 fi} END{print $1}' | awk -F':' '{print $1}'  #\u83b7\u53d6\u7f51\u5361\u540d\u79f0\n\nawk '$1 !~ \/lo\/' \/proc\/net\/dev | awk 'BEGIN{max=0} {if($2+0 &gt; max+0) max=$2 fi} END{print $1}' | awk -F':' '{print $1}'  #\u83b7\u53d6\u7f51\u5361\u540d\u79f0<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u6253\u5370\u6307\u5b9a\u884c Q:\u5982\u4f55\u7528awk\u6253\u5370\u67d0\u4e00\u6587\u4ef6\u7684\u7b2c3\u884c\u4e4b\u540e\u7684\u6240\u6709\u884c\uff1f A:\u53ef\u4ee5\u5229\u7528awk\u7684NR\u53d8\u91cf\u3002 \u641c\u7d22\u5173\u952e\u5b57 [&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],"class_list":["post-1984","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-tools","tag-awk"],"views":2843,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1984","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=1984"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1984\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=1984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=1984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=1984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}