Split text file into multiple files

醉酒当歌 提交于 2020-01-13 08:15:30

问题


I am having large text file having 1000 abstracts with empty line in between each abstract . I want to split this file into 1000 text files. My file looks like

16503654    Three-dimensional structure of neuropeptide k bound to dodecylphosphocholine micelles.      Neuropeptide K (NPK), an N-terminally extended form of neurokinin A (NKA), represents the most potent and longest lasting vasodepressor and cardiomodulatory tachykinin reported thus far.  

16504520    Computer-aided analysis of the interactions of glutamine synthetase with its inhibitors.        Mechanism of inhibition of glutamine synthetase (EC 6.3.1.2; GS) by phosphinothricin and its analogues was studied in some detail using molecular modeling methods. 

回答1:


You can use split and set "NUMBER lines per output file" to 2. Each file would have one text line and one empty line.

split -l 2 file



回答2:


You could always use the csplit command. This is a file splitter but based on a regex.

something along the lines of :

csplit -ks -f /tmp/files INPUTFILENAMEGOESHERE '/^$/'

It is untested and may need a little tweaking though.

CSPLIT




回答3:


Something like this:

awk 'NF{print > $1;close($1);}' file

This will create 1000 files with filename being the abstract number. This awk code writes the records to a file whose name is retrieved from the 1st field($1). This is only done only if the number of fields is more than 0(NF)



来源:https://stackoverflow.com/questions/16273069/split-text-file-into-multiple-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!