Xref: utzoo comp.unix.wizards:24892 comp.lang.perl:4915 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!psuvax1!news From: flee@cs.psu.edu (Felix Lee) Newsgroups: comp.unix.wizards,comp.lang.perl Subject: Re: Word-oriented GREP Message-ID: Date: 15 Apr 91 15:12:09 GMT References: <1991Apr15.014626.28903@berlioz.nsc.com> <1991Apr15.044312.27326@iwarp.intel.com> Sender: news@cs.psu.edu (Usenet) Distribution: na Organization: ~/News/org Lines: 22 Nntp-Posting-Host: dictionopolis.cs.psu.edu (from comp.unix.questions) | When I use the command "grep V\[0-9\]\[0-9\]\[0-9\] fred.c" it returns | #define VERSION "V002" | or somesuch. What I would really like is just the string of characters | which matched: | V002 I've wanted an "xgrep" tool for a while. It would scan an input stream for a pattern and print any part of the stream that matches. Randal Schwartz offers a Perl solution, but you can't escape line boundaries. Consider the pattern ^(.*\n){0,3}.*Able.*(\n.*){0,3}$ which means, print three lines of context around any line that contains "Able". Generalized context grep. You can write patterns for any type of simple context. (You can actually do this in Perl, but it becomes extremely inefficient for large files, because you can only apply patterns to strings, not streams.) -- Felix Lee flee@cs.psu.edu