2023-05-27

Split text file into smaller multiple text file using command line

You can use:

split -l 5000 filename.txt

That creates files:

xaa
xab
aac
xad
xbe
aaf

Or you can use:

split -l 5000 -d --additional-suffix=.txt $FileName file

Where:

  • -l 5000: split file into files of 5,000 lines each.
  • -d: numerical suffix. This will make the suffix go from 00 to 99 by default instead of aa to zz.
  • --additional-suffix: lets you specify the suffix, here the extension
  • $FileName: name of the file to be split.
  • file: prefix to add to the resulting files.
Use man split for more info

P.S: Borrowed from here

Happy hacking!!!

No hay comentarios: