Geospatial Modelling Environment

file.countlines (Count Lines In Text File)

Counts the number of lines in a text file


This tool counts the number of lines in a text file, with the option of only counting lines that contain a specified search string. This can be useful when dealing with large XML files for instance when you might wish to determine the number of features the XML file contains. It is also useful when used in conjunction with the file.readlines and file.extractlines tool when you are interested in viewing or extracting data from the end of a large text file.

The 'match' option requires that you specify a search string. If a line in the input file contains this string anywhere within that line it is included in the count. Note that the search string is interpreted literally, and does not interpret any characters as wildcards (e.g. *).

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.countlines(file, [match]);

filethe full path to the input text file
[match]if specified counts only the the lines containing this string



file.countlines(file="C:\data\roads.gml", 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