Geospatial Modelling Environment

file.readlines (Read Lines From Text FIle)

Extracts a specified range of lines from a textfile and writes them to the output window


This tool extracts a specified range of lines from a text file and writes them to the output window in this tool. It was designed to provide a way of inspecting text files (e.g. XML or GML files) that are so large they cannot be conveniently opened in other software. The user specifies a start and end line that defines the range of lines to read. If the end line specified is larger than the number of lines in the file the tool will read all lines from the specified start line to the end of the file. The file.countlines tool can be used to determine the total number of lines in the text file, which is useful if you wish to read the last lines in the file. This tool is also useful for determining if text data files have header lines (e.g. read the first 10 lines).

Note that this tool is similar to the file.extractlines tool but writes the lines to the output window rather than a different file. The advantage of this is that it allow faster inspection of a file, but if the file contains special characters then there is a risk it will not be displayed properly in the output window. The file.extractlines tool is better if you want a precise extraction whereas this tool is more useful for a quick but potentially imprecise investigation. XML and GML files can be particularly problematic with this tool, but data files are usually fine.

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.readlines(file, start, end);

filethe full path to the text file
startthe line number to start reading
endthe line number to end reading


file.readlines(file=”C:dataroads.gml”, start=1, end=100);


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