From owner-freebsd-questions@FreeBSD.ORG Sat Dec 10 06:39:34 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0E17316A41F for ; Sat, 10 Dec 2005 06:39:34 +0000 (GMT) (envelope-from penryu@saiyix.ath.cx) Received: from mtai02.charter.net (mtai02.charter.net [209.225.8.182]) by mx1.FreeBSD.org (Postfix) with ESMTP id 302EB43D55 for ; Sat, 10 Dec 2005 06:39:33 +0000 (GMT) (envelope-from penryu@saiyix.ath.cx) Received: from mxip21-10.charter.net ([10.20.202.71]) by mtai02.charter.net (InterMail vM.6.01.05.04 201-2131-123-105-20051025) with ESMTP id <20051210063932.UITF10683.mtai02.charter.net@mxip21-10.charter.net> for ; Sat, 10 Dec 2005 01:39:32 -0500 Received: from 66-214-103-59.dhcp.reno.nv.charter.com (HELO saiyix.ath.cx) ([66.214.103.59]) by mxip21-10.charter.net with ESMTP; 10 Dec 2005 01:39:32 -0500 X-BrightmailFiltered: true X-Brightmail-Tracker: AAAAAQAAA+k= Received: by saiyix.ath.cx (Postfix, from userid 1000) id 0DF8114254; Fri, 9 Dec 2005 22:39:31 -0800 (PST) Date: Fri, 9 Dec 2005 22:39:31 -0800 From: Tim Hammerquist To: freebsd-questions@freebsd.org Message-ID: <20051210063930.GC3836@ruri> Mail-Followup-To: freebsd-questions@freebsd.org References: <200512092212.jB9MCQhn092277@dc.cis.okstate.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <200512092212.jB9MCQhn092277@dc.cis.okstate.edu> X-Editor: Vim-603 http://www.vim.org/ User-Agent: Mutt/1.5.9i Subject: Re: Regular Expression Trouble X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: penryu@saiyix.ath.cx List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Dec 2005 06:39:34 -0000 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