Geospatial Modelling Environment

file.split (Split Text File)

Splits a text file into multiple, approximately equally sized, smaller text files


This tool splits a text file into multiple, approximately equally sized, smaller text files. There are two optional arguments that make this a particularly useful command in certain situations. First, the ‘hdr’ option allows you to specify the number of lines that make up the header of the file that will also be written as the header of split files (thus preserving the header among all the files). For many data files this will just be ‘hdr=1’, but for some XML and GML file format the headers can occupy several dozen lines.

The second optional argument is ‘match’, which ensures a file is only split immediately following lines containing the match search string. In data files this will not normally be useful (because each line represents a different record and it does not matter where the break in lines occurs). But in XML or GML files a single record can occupy multiple lines, so it is important that breaks occur only at appropriate places.

If the output folder does not exist, the tool will attempt to create it. If any of the output files already exist, an error is generated and the tool stops.

A number of tools have been developed to manipulate text files. They were developed to make it more efficient to import datasets delivered in text file format (e.g. weather datasets that are delivered as separate files for each year, or XML files containing spatial data), but are likely to be useful for a wide range of tasks. See the commands beginning with ‘file’ for further information.


file.split(file, folder, prefix, cnt, [hdr], [match]);

filethe full path to the input text file
folderthe output folder
prefixthe file name prefix of the output files
cntthe number of output files to create (the input file is split between them)
[hdr]the number of header lines from the beginning of the file to include in each output file (default=0)
[match]breaks the file only on lines containing this string (unspecified by default)


file.split(file=”C:dataroads.gml”, folder=”C:datanewroads”, prefix=”roads”, cnt=5);

file.split(file=”C:dataroads.gml”, folder=”C:datanewroads”, prefix=”roads”, cnt=5, hdr=7, match=”ENDOFRECORD”);


Please consider making a purchase to support the continued development of these tools  Read more...

Tips on how to use this interface efficiently 


Open Source GIS

Copyright © 2001-2014 Hawthorne L. Beyer, Ph.D., Spatial Ecology LLC    Connect on LinkedIn