4

Is there a way to give custom filenames for split command? I am splitting a file that is 100GB into chunks of 128MB. Here is what I am doing

split -b 128000k mydata.csv.

This creates files with following names xaa,xab,xac,.. etc. I am wondering if it is possible to have custom names like mydata_0.csv, mydata_1.csv for each of the splits.

xhienne
  • 17,075
  • 2
  • 52
  • 68
brain storm
  • 141
  • 1
  • 3

1 Answers1

11

Yes, with GNU split you can achieve this:

split -d -a3 -b 128M --additional-suffix=.csv mydata.csv mydata_

Explanation:

  • -d -a3: use a numerical index with 3 digits
  • -b 128M: split in 128 MB chunks
  • --additional-suffix=.csv: add a .csv extension
  • the trailing mydata_ is the prefix
xhienne
  • 17,075
  • 2
  • 52
  • 68
  • 1
    in centos, I get `split: unrecognized option '--additional-suffix=.csv'` – brain storm Jan 18 '17 at 18:28
  • @brainstorm The option was added to GNU `split` in 2012. `split --version` yields me 8.21. If your version is not GNU or too old, see [this answer](http://unix.stackexchange.com/a/32630/203203) – xhienne Jan 18 '17 at 18:32