搜索关键字:
- use awk to split file
参考链接:
- http://unix.stackexchange.com/questions/46325/how-can-i-split-a-text-file-into-multiple-text-files
- http://superuser.com/questions/485189/using-awk-to-split-text-file-every-10-000-lines
- 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.unixcl.com/2009/09/split-file-using-awk-few-examples.html
- http://www.catonmat.net/blog/ten-awk-tips-tricks-and-pitfalls/
- http://www.theunixschool.com/2012/06/awk-10-examples-to-split-file-into.html
- http://stackoverflow.com/questions/11313852/split-one-file-into-multiple-files-based-on-delimiter
- http://www.unix.com/shell-programming-and-scripting/251156-split-big-file-into-multiple-files-using-awk.html
- http://www.folkstalk.com/2015/02/split-file-using-awk-command-unix-linux.html
参考解答:
$ cat entry.txt [ entry1 ] 1239 1240 1242 1391 1392 1394 1486 1487 1489 1600 1601 1603 1657 1658 1660 2075 2076 2078 2322 2323 2325 2740 2741 2743 3082 3083 3085 3291 3292 3294 3481 3482 3484 3633 3634 3636 3690 3691 3693 3766 3767 3769 4526 4527 4529 4583 4584 4586 4773 4774 4776 5153 5154 5156 5628 5629 5631 [ entry2 ] 1239 1240 1242 1391 1392 1394 1486 1487 1489 1600 1601 1603 1657 1658 1660 2075 2076 2078 2322 2323 2325 2740 2741 2743 3082 3083 3085 3291 3292 3294 3481 3482 3484 3690 3691 3693 3766 3767 3769 4526 4527 4529 4583 4584 4586 4773 4774 4776 5153 5154 5156 5628 5629 5631 [ entry3 ] 1239 1240 1242 1391 1392 1394 1486 1487 1489 1600 1601 1603 1657 1658 1660 2075 2076 2078 2322 2323 2325 2740 2741 2743 3082 3083 3085 3291 3292 3294 3481 3482 3484 3690 3691 3693 3766 3767 3769 4241 4242 4244 4526 4527 4529 4583 4584 4586 4773 4774 4776 5153 5154 5156 5495 5496 5498 5628 5629 5631 $ gawk '/^\[/{match($0, /^\[ (.+?) \]/, k)} {print >k[1]".txt" }' entry.txt $ ls -l entry1.txt entry2.txt entry3.txt $ head -2 zmap_scan.csv 192.116.245.191, 3306, synack, 2015-04-30T18:36:49.813+0800 10.140.41.38, 27017, synack, 2015-04-30T18:36:49.814+0800 $ awk -F', ' '{print > "port_"$2}' zmap_scan.csv $ ls -l port_3306 port_27017
==
《“用awk拆分文件”》 有 1 条评论
简单的命令行工具——将csv文件转换成可以搜索和排序的HTML表格
https://github.com/vividvilla/csvtotable