From owner-freebsd-questions@FreeBSD.ORG Mon May 17 09:25:56 2004 Return-Path: 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 CED8816A4CE for ; Mon, 17 May 2004 09:25:56 -0700 (PDT) Received: from relay01.roc.ny.frontiernet.net (relay01.roc.ny.frontiernet.net [66.133.131.34]) by mx1.FreeBSD.org (Postfix) with ESMTP id D0A7843D1F for ; Mon, 17 May 2004 09:25:55 -0700 (PDT) (envelope-from drew@mykitchentable.net) Received: (qmail 1031 invoked from network); 17 May 2004 16:25:55 -0000 Received: from 67-51-156-100.dsl1.elk.ca.frontiernet.net (HELO blacklamb.mykitchentable.net) ([67.51.156.100]) (envelope-sender )SMTP for ; 17 May 2004 16:25:55 -0000 Received: from [165.107.42.233] (unknown [165.107.42.233]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by blacklamb.mykitchentable.net (Postfix) with ESMTP id B0E5B3BF36A; Mon, 17 May 2004 09:25:50 -0700 (PDT) Message-ID: <40A8E794.6040309@mykitchentable.net> Date: Mon, 17 May 2004 09:25:56 -0700 From: Drew Tomlinson User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Erik Trulsson References: <40A8D6A5.5090705@mykitchentable.net> <20040517153636.GA23982@falcon.midgard.homeip.net> In-Reply-To: <20040517153636.GA23982@falcon.midgard.homeip.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: FreeBSD Questions Subject: Re: grep & RegEx Syntax- How to Match? -- SOLVED X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2004 16:25:56 -0000 On 5/17/2004 8:36 AM Erik Trulsson wrote: >On Mon, May 17, 2004 at 08:13:41AM -0700, Drew Tomlinson wrote: > > >>I've learned a little about regular expressions and am trying to use >>them with grep. I want to parse my httpd log to return entries that >>contain a particular IP address and file ending in .htm or .html. I >>want to match lines like this one: >> >>123.456.789.123 - - [17/May/2004:06:54:53 -0700] "GET >>/public/murphys/produced/tricks.html HTTP/1.0" 200 5446 "-" >>"Mozilla/4.77 [en] (X11; U; Linux 2.2.19 i686)" >> >> > >Is that supposed to be a single line, or is it actually three lines in >the log. >That matters because grep works on lines. >I will assume that it is only line in the log. > > Sorry. Yes, one single line. >>I'm using the this command: >> >>egrep -e ^123\.456\.789\.123.*htm.* /path/to/file >> >> > >Try quoting the argument given to egrep, otherwise your shell might try >to expand '*' as a wildcard. >I.e. try > >egrep -e '^123\.456\.789\.123.*htm.*' /path/to/file > > Thank you! Yes, this works as I expect. >>However this does not match anything. If I shorten the regex to >>^123\.456\.789\.123, I match all entries with that IP address. And if I >>use 'htm' as the regex, I get match all lines with html files. But I >>can't find the right syntax to match on both conditions. >> >> > >You could try piping the output from the first grep into a second grep. >For example: > >grep '^123\.456\.789\.123' /path/to/file | grep 'htm' > > Another good idea. Thanks for your help! Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, & More! http://www.alchemistswarehouse.com