How to split into files with a given number of lines or occurrences

It may be difficult to open a very large text file (like server logs) into a text editor program without crashing your system (not enough memory for instance); in this case you can split this large text file into smaller ones and open these files.

img Click on "Type and Size" and "Blocked Pieces". Then select "I want to split before / after the nth occurrence of a specified pattern".

img Enter the exact number of lines or occurrences you want to put in each piece file.

img Type the pattern that GSplit should search for. GSplit will analyze the original file and increase an internal counter each time the pattern is found. When the counter has reached the number of occurrences you specified, a new piece file is created.

To tell GSplit to split before or after a given number of lines, enter this pattern (see below why):


Hint: if you are splitting a text file, you can also configure GSplit so it doesn't add piece headers to files: see this topic.

Kinds of allowed patterns

img A pattern can contain alphanumeric characters only. To specify other characters not normally permitted, you must use the "0x" command followed by the 2-digit hexadecimal sequence that refers to the corresponding ASCII character code you want. Example: 0x40 denotes the @ character. You can use characters from 0x00 to 0xFF ; see the ASCII table here. The 2 digits must be specified: 0xA is incorrect, use 0x0A. Unicode sequences are not supported.

img Patterns may have up to 256 characters.

img Examples of patterns:

img If you are splitting a log file, a CSV file or any text file with a header, you may also want to insert a header in each piece file.