{"id":2132,"date":"2015-05-10T22:15:06","date_gmt":"2015-05-10T14:15:06","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2132"},"modified":"2015-05-10T22:15:06","modified_gmt":"2015-05-10T14:15:06","slug":"%e7%94%a8awk%e6%8b%86%e5%88%86%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2132.html","title":{"rendered":"\u7528awk\u62c6\u5206\u6587\u4ef6"},"content":{"rendered":"<p><strong>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/strong><\/p>\n<ul>\n<li>use awk to split file<\/li>\n<\/ul>\n<p><strong>\u53c2\u8003\u94fe\u63a5\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/46325\/how-can-i-split-a-text-file-into-multiple-text-files\">http:\/\/unix.stackexchange.com\/questions\/46325\/how-can-i-split-a-text-file-into-multiple-text-files<\/a><\/li>\n<li><a href=\"http:\/\/superuser.com\/questions\/485189\/using-awk-to-split-text-file-every-10-000-lines\">http:\/\/superuser.com\/questions\/485189\/using-awk-to-split-text-file-every-10-000-lines<\/a><\/li>\n<li><a href=\"http:\/\/www.linuxquestions.org\/questions\/linux-newbie-8\/how-can-i-split-a-file-into-many-files-using-a-string-in-awk-or-sed-4175464847\/\">http:\/\/www.linuxquestions.org\/questions\/linux-newbie-8\/how-can-i-split-a-file-into-many-files-using-a-string-in-awk-or-sed-4175464847\/<\/a><\/li>\n<li><a href=\"http:\/\/www.unixcl.com\/2009\/09\/split-file-using-awk-few-examples.html\">http:\/\/www.unixcl.com\/2009\/09\/split-file-using-awk-few-examples.html<\/a><\/li>\n<li><a href=\"http:\/\/www.catonmat.net\/blog\/ten-awk-tips-tricks-and-pitfalls\/\">http:\/\/www.catonmat.net\/blog\/ten-awk-tips-tricks-and-pitfalls\/<\/a><\/li>\n<li><a href=\"http:\/\/www.theunixschool.com\/2012\/06\/awk-10-examples-to-split-file-into.html\">http:\/\/www.theunixschool.com\/2012\/06\/awk-10-examples-to-split-file-into.html<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/11313852\/split-one-file-into-multiple-files-based-on-delimiter\">http:\/\/stackoverflow.com\/questions\/11313852\/split-one-file-into-multiple-files-based-on-delimiter<\/a><\/li>\n<li><a href=\"http:\/\/www.unix.com\/shell-programming-and-scripting\/251156-split-big-file-into-multiple-files-using-awk.html\">http:\/\/www.unix.com\/shell-programming-and-scripting\/251156-split-big-file-into-multiple-files-using-awk.html<\/a><\/li>\n<li><a href=\"http:\/\/www.folkstalk.com\/2015\/02\/split-file-using-awk-command-unix-linux.html\" target=\"_blank\">http:\/\/www.folkstalk.com\/2015\/02\/split-file-using-awk-command-unix-linux.html<\/a><\/li>\n<\/ul>\n<p><strong>\u53c2\u8003\u89e3\u7b54\uff1a<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$ cat entry.txt\n[ entry1 ]\n1239 1240 1242 1391 1392 1394 1486 1487 1489 1600\n1601 1603 1657 1658 1660 2075 2076 2078 2322 2323\n2325 2740 2741 2743 3082 3083 3085 3291 3292 3294\n3481 3482 3484 3633 3634 3636 3690 3691 3693 3766\n3767 3769 4526 4527 4529 4583 4584 4586 4773 4774\n4776 5153 5154 5156 5628 5629 5631\n[ entry2 ]\n1239 1240 1242 1391 1392 1394 1486 1487 1489 1600\n1601 1603 1657 1658 1660 2075 2076 2078 2322 2323\n2325 2740 2741 2743 3082 3083 3085 3291 3292 3294\n3481 3482 3484 3690 3691 3693 3766 3767 3769 4526\n4527 4529 4583 4584 4586 4773 4774 4776 5153 5154\n5156 5628 5629 5631\n[ entry3 ]\n1239 1240 1242 1391 1392 1394 1486 1487 1489 1600\n1601 1603 1657 1658 1660 2075 2076 2078 2322 2323\n2325 2740 2741 2743 3082 3083 3085 3291 3292 3294\n3481 3482 3484 3690 3691 3693 3766 3767 3769 4241\n4242 4244 4526 4527 4529 4583 4584 4586 4773 4774\n4776 5153 5154 5156 5495 5496 5498 5628 5629 5631\n\n$ gawk '\/^\\[\/{match($0, \/^\\[ (.+?) \\]\/, k)} {print &gt;k[1]\".txt\" }' entry.txt\n$ ls -l\nentry1.txt\nentry2.txt\nentry3.txt\n\n$ head -2 zmap_scan.csv\n192.116.245.191, 3306, synack, 2015-04-30T18:36:49.813+0800\n10.140.41.38, 27017, synack, 2015-04-30T18:36:49.814+0800\n\n$ awk -F', ' '{print &gt; \"port_\"$2}' zmap_scan.csv\n$ ls -l\nport_3306\nport_27017<\/pre>\n<p>==<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u641c\u7d22\u5173\u952e\u5b57\uff1a use awk to split file \u53c2\u8003\u94fe\u63a5\uff1a http:\/\/unix.stackexc [&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,7,12],"tags":[74],"class_list":["post-2132","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","category-tools","tag-awk"],"views":3242,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2132","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=2132"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2132\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}