Xref: utzoo comp.unix.questions:30389 comp.lang.perl:4909 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!mintaka!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.unix.questions,comp.lang.perl Subject: Re: Word-oriented GREP Message-ID: <1991Apr15.044312.27326@iwarp.intel.com> Date: 15 Apr 91 04:43:12 GMT References: <1991Apr15.014626.28903@berlioz.nsc.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Followup-To: comp.unix.questions Distribution: na Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 33 In-Reply-To: nelson@berlioz.nsc.com (Taed Nelson) In article <1991Apr15.014626.28903@berlioz.nsc.com>, nelson@berlioz (Taed Nelson) writes: | 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 thought about it for a while, and I couldn't come up with anything; even | AWK seems to offer no nice way of doing it, but this seems like something | that is at least somewhat common... | Does anyone have any suggestions, preferably limiting the solution to SH or | CSH, and by not using uncommon tools such as PERL? It's such a natural task for Perl, as in: print -ne 'print "$&\n" if /V\d\d\d/' fred.c If you have multiple occurrances, you can do the slightly more arcane: print -ne 's/V\d\d\d/print "$&\n"/eg' fred.c By the way, if you find Perl to be "uncommon", I suggest you make yourself more aware of it. It's everywhere these days. For example, there exists at least one computer manufacturer that has it installed at sysgen time, and it's part of the GNU utils tape. And because it's free, and highly (even overly :-) portable, you can put it up yourself if necessary. print "Just another Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/