Description
This tool extracts a specified range of lines from a text file and writes them to a new file. 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 extract. If the end line specified is larger than the number of lines in the file the tool will extract 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 extract the last line in the file. This tool is also useful for determining if text data files have header lines (e.g. extract the first 10 lines).
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.
Syntax
file.extractlines(file, newfile, start, end);
| file | the full path to the text file | |
| newfile | the full path to the new text file to create | |
| start | the line number to start reading/writing | |
| end | the line number to end reading/writing |
Example
file.extractlines(file="C:\data\roads.gml", newfile="C:\data\roads.txt", start=100, end=250);