count

Counts the number of lines containing an occurrence of one regular expression in a file before another regular expression is encountered.

Syntax

count("regexp1", "regexp2")

Inputs

regexp1
The regular expression to count
regexp2
The regular expression marking the end of the search

Comments

This function counts the number of lines containing text which matches the specified regular expression, not the number of occurrences of that expression.

count stops searching when it encounters a line containing regexp2 or when it reaches the end of the file. The current file position will either be the start of the line containing regexp2 or the end of the file.

If regexp1 is never found, count generates a failure condition.

Like all functions, count can only be used on the right-hand side of a set statement.

Examples

set items = count("item #[0-9]+", "end items")