Created
July 14, 2017 01:38
-
-
Save suplo/c3eff82edab317f6e4a50cc943f7fcae to your computer and use it in GitHub Desktop.
Split a file into multiple chunk by lines count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/questions/40509083/vim-split-one-file-into-multiple-files-based-on-row-count | |
up vote | |
8 | |
down vote | |
accepted | |
First, you define a control variable: | |
:let i = 1 | |
Then, you write lines 1 to 99 (inclusive) to a file named after the current value of the control variable, cut those line, and increment the control variable; | |
:exec "1,99w! chunk-" . i|1,99d|let i = i + 1 | |
Repeat as many times as needed: | |
49@: | |
This should give you 50 files named chunk-1 to chunk-50. | |
Since 5000 is not divisible by 99 you will be left with 50 lines. Write them to chunk-51: | |
:w chunk-51 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment