0

I use Debian and I have a text file and I want to split that into several files with specific suffix name and size. I want split that file by n chunk therefore, I should use -n option. How can I do that with split command? Thanks

fedora
  • 41
  • Split it by what , paragraphs, lines or something else ? Do you want to do the splitting in the text editor or in the terminal ? – Angel May 04 '19 at 18:28
  • Perhaps you can give us a sample suffix name and size so that answerers can get close to an actual Answer for you? – Jeff Schaller May 04 '19 at 18:29
  • Also; what operating system are you using? POSIX split does not allow for a custom suffix (natively). – Jeff Schaller May 04 '19 at 18:31
  • Thanks dears, I edited my post. – fedora May 04 '19 at 18:36
  • Any reason you can't just first use split with specific size, and then rename all of them afterwards? For example with rename from the Debian package rename (which can rename multiple files at once, according to a pattern). – dirkt May 04 '19 at 18:48
  • So I can't split the file into specific size and specific suffix name simultaneously with split command? – fedora May 04 '19 at 18:52

1 Answers1

3

With split (GNU coreutils) you could split file into N chunks split00.part, split01.part, ... split[N-1].part:

  • by size - lines can be splitted "into two halves", but all parts have the same size

    split -d -nN --additional-suffix=.part file split
    
  • at whole lines/records - parts may slightly differ in size

    split -d -nl/N --additional-suffix=.part file split
    
  • or split by defined size of chunks in bytes like 1MiB

    split -d -b1048576 --additional-suffix=.part file split
    
Freddy
  • 25,565