Mapping Toolbox    
grepfields

Identify matching fields in fixed record length files

Syntax

Description

grepfields(filename,searchstring) displays lines in the file that begin with the search string. The file must have fixed length records with line endings.

grepfields(filename,searchstring,casesens), with casesens 'matchcase' specifIes a case-sensitive search. If omitted or 'none', the search string will match regardless of the case.

grepfields(filename,searchstring,casesens,startcol) searches starting with the specified column. startcol is an integer between 1 and the bytes-per-record in the file. In this calling form, the file is regarded as a text file with line endings.

grepfields(filename,searchstring,casesens,startfield,fields) searches within the specified field. startfield is an integer between 1 and the number of fields-per-record. The format of file is described by the fields structure. See readfields for recognized fields structure entries. In this calling form, the file can be binary and lack line endings. The search is within startfield, which must be a character field.

grepfields(filename,searchstring,casesens,startfield,fields, machineformat) opens the file with the specified machine format. machineformat must be recognized by fopen.

indx = grepfields(...) returns the record numbers of matched records instead of displaying them on-screen.

Example

Write a binary file and read it

Find the record matching the string 'character2'. The record contains binary data, which cannot be properly displayed.

Read the formatted file containing the following:

--------------------------------------------------------

character data 1 1 2 3 1e6 10D6

character data 2 11 22 33 2e6 20D6

character data 3111222333 3e6 30D6

--------------------------------------------------------

Find the records which match at the beginning of the line.

Find the record which match, starting the search in column 11.

Search record number 1.

Limitations

Searches are limited to field containing character data.

Remarks

See readfields for a complete discussion of the format and contents of the fields argument.

See Also
readfields
Read fields or records from a fixed format file


  gradientm gridm