Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!fitz From: fitz@mml0.meche.rpi.edu (Brian Fitzgerald) Newsgroups: comp.unix.questions Subject: Re: Word-oriented GREP Message-ID: Date: 15 Apr 91 04:25:20 GMT References: <1991Apr15.014626.28903@berlioz.nsc.com> Distribution: na Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 29 Nntp-Posting-Host: mml0.meche.rpi.edu 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 Try: sed -n -e 's/.*\(V[0-9][0-9][0-9]\).*/\1/p' (use \[ and \] in csh) This just gets the first occurrence on a line, though. Wizards know how to print more than one occurrence with shell commands, even if they are not separated by white space. (i.e. V001,V002,...) Since I'm not a wizard, I tried lex: %% V[0-9][0-9][0-9] printf("%s\n",yytext); . | \n ; Save as foo.l and type "make LDLIBS=-ll foo" (or "lex -t foo.l > foo.c ; cc -o foo foo.c -ll") Brian