Date: Fri, 9 Dec 2005 22:39:31 -0800 From: Tim Hammerquist <penryu@saiyix.ath.cx> To: freebsd-questions@freebsd.org Subject: Re: Regular Expression Trouble Message-ID: <20051210063930.GC3836@ruri> In-Reply-To: <200512092212.jB9MCQhn092277@dc.cis.okstate.edu> References: <200512092212.jB9MCQhn092277@dc.cis.okstate.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
Martin McCormick wrote: > After reading a bit about extended regular expressions and > having a few actually work correctly in sed scripts, I tried one in > egrep and it isn't working although there are no errors. > > I was hoping to get only the A records from a dns zone file so > the expression I used is: > > egrep [[:space:]IN[:space:]A[:space:]] zone_file >h0 If you're using vi, put your cursor on that very first '[' and bounce on the % key for a while; see if anything occurs to you. If not, you could probably use a refresher course on that little sub-syntax of regular expressions called character classes. > It seems to match almost everything. The regex "[[:space:]IN[:space:]A[:space:]]" is composed entirely of one large character class. Classes are logical sets and have no interest in the order or quantity of their contents, so it's reduced to "[[:space:]AIN]". When fed to egrep, it says, "match any line which contains any of these 4 entities". Most lines will contain a space character, if not the 3 letters, so your output makes sense. As the [:space:] only has meaning inside brackets itself, it's improtant to open enclose each individual occurence inside it's own additional set of brackets. egrep "[[:space:]]IN[[:space:]]A[[:space:]]" zone_file >h0 HTH, Tim Hammerquist
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051210063930.GC3836>