Two days ago a friend said, want to implement a text file according to a fixed number of lines to split into multiple text files, but do not know how to achieve. If the amount of data is small manual segmentation is good, if the volume of data is very large, manual completion is too labor-intensive, also unrealistic. Then you need to use scripts to implement them. Since a friend wants to accomplish this task simply, it is better to record it and make it easier for a friend in need.
The following I use Python and PHP for the implementation and operation of the script, of course, in other languages can be achieved, you can according to the language of the familiarity of the independent choice, if a friend has not reached the ability to write code, then at least the use of the language environment will be, as long as the attainment of these, You can do the following work. The demo is as follows:
For example, we want to split the A.txt file into multiple txt files, separated by 5 lines.
A.txt file for the test data to be split, I created 21 data, as follows:
Each of the five lines is divided into 5 txt files, the following is the implementation of the Python script: split.py
Execute script: Python split.py
To view the execution results:
Look at the contents of 0.txt and 4.txt:
In this way 21 data is divided into 5 text files, the same data volume, only need to modify the script limit (a TXT file to split the number of bars), of course, the file format is not limited to txt,csv and so on, interested friends may wish to try.
The script written in PHP is as follows: It's not too much to describe here, and it's recommended to use Python.