27.11 A Multiline Context grep Using sed[One weakness of the grep family of programs is that they are line-oriented. They read only one line at a time, and so they can't find patterns (such as phrases) that are split across two lines. agrep (27.8 ) can do multiline searches. One advantage of the cgrep.sed script is that it shows how to handle multiple-line patterns in sed -and can be adapted for work other than searches. -JP ]
$ will find all lines containing the word system
in the file main.c
,
and show 10 additional lines of context above and below each match.
(The - cgrep -3 "awk.*perl" will find all occurrences of the word "awk" where it is followed by
the word "perl" somewhere within the next 3 lines.
The pattern can
be any
simple regular expression (26.4
)
,
with one notable exception:
because you can match across lines, you should use Article 34.17 explains how the script works. - |
|