Split text file into multiple files

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)


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


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

Tags:

Unix

Bash

Awk