help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with regular expression formation


From: Kam-Hung Soh
Subject: Re: help with regular expression formation
Date: Mon, 31 Mar 2008 17:20:31 -0700 (PDT)
User-agent: G2/1.0

On Apr 1, 5:23 am, "Mickey Ferguson" <address@hidden> wrote:
> I'm generating output from a grep command, which I then want to process in
> grep again, filtering out my unwanted text.  In this specific example, I
> want to filter out all lines that start with zero or more white space,
> followed by the comment characters "//".  Here is what I thought I would
> use:
>
> grep StopProductServices *.rul *.h | grep ^\s*[^/]
>
> The first grep obviously finds all occurrences of StopProductServices within
> all *.rul and *.h files.  Then that output is piped into grep, with the
> intent being to start at the beginning of the line (the caret), allow any
> amount of white space (zero or more), and then match only if the first
> non-white space charater is NOT a forward slash.  What it appears to be
> doing is to match the exact opposite of what I want.
>
> To break it down a little, I first produced the output from the first grep,
> which is used for the pipe:
>
> ->grep StopProductServices *.rul *.h
> NTService.rul://    FUNCTION:  StopProductServices(sProduct)
> NTService.rul:// 03/24/08 MSF - Make StopProductServices() take an
> additional parameter to
> NTService.rul:function StopProductServices(sProduct)
> NTService.rul:// 03/24/08 MSF - Make StopProductServices() take an
> additional parameter to
> NTService.rul:// Function: SafeStopProductServices
> NTService.rul:// 03/24/08 MSF - Make StopProductServices(),
> SafeStopProductServices() and
> NTService.rul:function SafeStopProductServices(sProduct)
> NTService.rul:  bServicesStopped = StopProductServices(sProduct);
> NTService.rul:// 03/24/08 MSF - Make StopProductServices(),
> SafeStopProductServices() and
> Setup.rul://              - Use Start... and StopProductServices() to stop
> VESTA and
> Setup.rul:// 03/31/08 MSF - Use Start... and StopProductServices() to stop
> VESTA and
> Setup.rul:// 03/31/08 MSF - Use Start... and StopProductServices() to stop
> VESTA and
> Setup.rul:  StopProductServices(@PRODUCT_NAME);
> Setup.rul:  StopProductServices(VESTA_VIEW);
> NTService.h:// 09/07/07 MSF - New functions StopProductServices(),
> NTService.h://                SafeStopProductServices() and
> DisableProductServices().
> NTService.h:// 03/24/08 MSF - Make StopProductServices(),
> SafeStopProductServices() and
> NTService.h:prototype StopProductServices(STRING);
> NTService.h:prototype SafeStopProductServices(STRING);
>
> Then I ran the full command, and you can see that the output is not at all
> what I expected:
>
> [11:06:39]: *** C:\WIP\VESTA\Installer\Script Files ***
> ->grep StopProductServices *.rul *.h | grep ^\s*[^/]
> NTService.rul://    FUNCTION:  StopProductServices(sProduct)
> NTService.rul:// 03/24/08 MSF - Make StopProductServices() take an
> additional parameter to
> NTService.rul:// 03/24/08 MSF - Make StopProductServices() take an
> additional parameter to
> NTService.rul:// Function: SafeStopProductServices
> NTService.rul:// 03/24/08 MSF - Make StopProductServices(),
> SafeStopProductServices() and
> NTService.rul:// 03/24/08 MSF - Make StopProductServices(),
> SafeStopProductServices() and
> Setup.rul://              - Use Start... and StopProductServices() to stop
> VESTA and
> Setup.rul:// 03/31/08 MSF - Use Start... and StopProductServices() to stop
> VESTA and
> Setup.rul:// 03/31/08 MSF - Use Start... and StopProductServices() to stop
> VESTA and
> NTService.h:// 09/07/07 MSF - New functions StopProductServices(),
> NTService.h://                SafeStopProductServices() and
> DisableProductServices().
> NTService.h:// 03/24/08 MSF - Make StopProductServices(),
> SafeStopProductServices() and
>
> Here is what I thought I would get:
>
> NTService.rul:function StopProductServices(sProduct)
> NTService.rul:function SafeStopProductServices(sProduct)
> NTService.rul:  bServicesStopped = StopProductServices(sProduct);
> Setup.rul:  StopProductServices(@PRODUCT_NAME);
> Setup.rul:  StopProductServices(VESTA_VIEW);
> NTService.h:prototype StopProductServices(STRING);
> NTService.h:prototype SafeStopProductServices(STRING);

Try: "grep -v ^\s*/"

which means: ignore all lines whose first non-whitespace character is
forward slash.

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog";>Software Salariman</
a>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]