grep .. -m .. stop reading a file…

Stop reading a file after NUM matching lines.
$grep -m 1  wc  wcwidth.c
$grep -m 2  wc  wcwidth.c
wchar_t cr;
$grep -m 3  wc  wcwidth.c
wchar_t cr;
$grep -m 4  wc  wcwidth.c
wchar_t cr;
$grep -m 0  wc  wcwidth.c
scripts/makelst - 338 identical

    19: t1=`$3 --syms $1 | grep .text | grep -m1 " F "`
    20: if [ -n "$t1" ]; then - GPL - Shell
Searching for a pattern in a text file is a very common operation
 in many applications ranging from text editors and databases to
 applications in molecular biology. In many instances the pattern
does not appear in the text exactly. Errors in the text or in the
 query can result from misspelling or from experimental errors
 (e.g., when the text is a DNA sequence). The use of such
 approximate pattern matching has been limited until now to
 specific applications. Most text editors and searching programs
 do not support searching with errors because of the com-
plexity involved in implementing it. In this paper we describe a
new tool, called agrep, for approximate pattern matching. Agrep
 is based on a new efficient and flexible algorithm for approximate
 string matching. Agrep is also competitive with other tools for
 exact string matching; it include many options that make
 searching more powerful and convenient.

source :

(Preliminary version)
Sun Wu and Udi Manber1
Department of Computer Science
University of Arizona
Tucson, AZ 85721
(sw | udi)