regular expressions

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

regular expressions

Postby tedius » Mon Feb 12, 2007 9:46 am

I have a structure with a member secno and I want to find all the files where a secno comparison is made. So I though that a egrep would do the job nicely, and I came up with this.

egrep ".*secno == .*secno.*" *.cc

Now I had run this command multiple times, changing the comparison function each time, i.e. ==, >, <, <=, >= and !=

Does anyone know if there is way I could have done all this with one regular expression rather than the 6 that I came up with.

Thanks
User avatar
tedius
 
Posts: 84
Joined: Fri Apr 08, 2005 3:20 pm
Location: Cambridge, England

RE: regular expressions

Postby MartyBartfast » Mon Feb 12, 2007 11:20 am

I think this will do what you want:

egrep ".*secno [=<>\!]=? .*secno.*" *.cc
User avatar
MartyBartfast
LXF regular
 
Posts: 820
Joined: Mon Aug 22, 2005 7:25 am
Location: Hants, UK

RE: regular expressions

Postby tedius » Mon Feb 12, 2007 11:28 am

That Marty,

No that was my first attempt too, but that will also give you assignment.

I've now found a way though

egrep "secno (==|(<|>|\!)=?) .*secno" *.cc
User avatar
tedius
 
Posts: 84
Joined: Fri Apr 08, 2005 3:20 pm
Location: Cambridge, England


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests