Xref: utzoo comp.unix.wizards:8863 comp.unix.questions:7278 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!bu-cs!bzs From: bzs@bu-cs.BU.EDU (Barry Shein) Newsgroups: comp.unix.wizards,comp.unix.questions Subject: Re: grep replacement Message-ID: <22969@bu-cs.BU.EDU> Date: 27 May 88 19:59:55 GMT References: <7882@alice.UUCP> <5630@umn-cs.cs.umn.edu> <6866@elroy.Jpl.Nasa.Gov> <2978@ihlpe.ATT.COM> <1463@laidbak.UUCP> Organization: Boston U. Comp. Sci. Lines: 31 In-reply-to: daveb@laidbak.UUCP's message of 27 May 88 04:08:03 GMT 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