grep replacement
Barry Shein
bzs at bu-cs.BU.EDU
Sat May 28 05:59:55 AEST 1988
Re: grep with N context lines shown...
Interesting, that's very close to a concept of a multi-line record
grep where I treat N lines as one and any occurrance results in a
listing. The difference is the line chosen to count from (in a context
the match would probably be middle and +-N, in a record you'd just
list the record.)
Just wondering if a generalization is being missed here somewhere,
also consider grepping something like a termcap file, maybe what I
really want is a generalized method to supply pattern matchers for
what to list on a hit:
grep -P .+3,.-3 pattern # print +-3 lines centered on match
grep -P ?^[^ \t]?,.+1 pattern # print from previous line not
# beginning with white space to
# one past current line
Of course, that destroys the stream nature of grep, it has to be able
to arbitrarily back up, ugh, although "last candidate for a start"
could be saved on the fly. The nice thing is that it can use
(essentially) the same pattern machinery for choosing printing (I
know, have to add in the notion of dot etc.)
I dunno, food for thought, like I said, maybe there's a generalization
here somewhere. Or maybe grep should just emit line numbers in a form
which could be post-processed by sed for fancier output (grep in
backquotes on sed line.) Therefore none of this is necessary :-)
-Barry Shein, Boston University
More information about the Comp.unix.questions
mailing list