Word-oriented GREP
Paul Falstad
pfalstad at phoenix.Princeton.EDU
Mon Apr 15 13:33:23 AEST 1991
nelson at 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 at 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.
More information about the Comp.unix.questions
mailing list