How to split one text file into multiple *.txt files?

前端 未结 9 654
[愿得一人]
[愿得一人] 2020-12-07 17:39

I got a text file file.txt(12 MBs) containing:

something1
something2
something3
something4
(...)

Is there any way to split

9条回答
  •  天涯浪人
    2020-12-07 18:23

    I agree with @CS Pei, however this didn't work for me:

    split -b=1M -d file.txt file

    ...as the = after -b threw it off. Instead, I simply deleted it and left no space between it and the variable, and used lowercase "m":

    split -b1m -d file.txt file

    And to append ".txt", we use what @schoon said:

    split -b=1m -d file.txt file --additional-suffix=.txt

    I had a 188.5MB txt file and I used this command [but with -b5m for 5.2MB files], and it returned 35 split files all of which were txt files and 5.2MB except the last which was 5.0MB. Now, since I wanted my lines to stay whole, I wanted to split the main file every 1 million lines, but the split command didn't allow me to even do -100000 let alone "-1000000, so large numbers of lines to split will not work.

提交回复
热议问题