Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!princeton!phoenix.Princeton.EDU!pfalstad From: pfalstad@phoenix.Princeton.EDU (Paul Falstad) Newsgroups: comp.unix.questions Subject: Re: Word-oriented GREP Message-ID: <8283@idunno.Princeton.EDU> Date: 15 Apr 91 03:33:23 GMT References: <1991Apr15.014626.28903@berlioz.nsc.com> Sender: news@idunno.Princeton.EDU Distribution: na Organization: League For Fighting Chartered Accountancy Lines: 27 nelson@berlioz.nsc.com (Taed Nelson) wrote: >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... It would seem so, but this is the simplest thing I could come up with: sed -n 's/.*V\([0-9][0-9][0-9]\).*/V\1/p' fred.c or (better, I think): grep 'V[0-9][0-9][0-9]' fred.c | sed 's/.*V\([0-9][0-9][0-9]\).*/V\1/' Doesn't work for multiple occurrences of Vxxx though. I seem to remember something out of the perl man page which makes this really simple. Someone will post it perhaps. -- Paul Falstad pfalstad@phoenix.princeton.edu And on the roads, too, vicious gangs of KEEP LEFT signs! If Princeton knew my opinions, they'd have expelled me long ago.