Regular expression: matching one string and not the other
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Regular expression: matching one string and not the other




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Regular expression: matching one string and not the other  
Timur Tabi


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 01:35 AM

I currently have the following command:

find . -name "*\.[CH]" | grep -v /src/menu/

This gives me a list of all files that end in .C or .H but do not have
the string "/src/menu" in them.

This works, but I'm trying to eliminate the call to grep.  I need a
regular expression that combines "*\.[CH]" with "-v /src/menu".  I've
searched for examples on the web and usenet, but I still can't figure
it out.  How do I do a logical-AND with regular expressions?





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 06:35 AM

On Wed, 21 Apr 2004 at 00:11 GMT, Timur Tabi wrote:
> I currently have the following command:
>
> find . -name "*\.[CH]" | grep -v /src/menu/
>
> This gives me a list of all files that end in .C or .H but do not have
> the string "/src/menu" in them.
>
> This works, but I'm trying to eliminate the call to grep.  I need a
> regular expression that combines "*\.[CH]" with "-v /src/menu".  I've
> searched for examples on the web and usenet, but I still can't figure
> it out.  How do I do a logical-AND with regular expressions?

If you wanted to eliminate by filename, it would be possible; find
matches only on the filename portion, not the full path.

--
Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
Robert Bonomi


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 06:35 AM

In article <53bb806a.0404201611.62515918@posting.google.com>,
Timur Tabi <nospam_timur@tabi.org> wrote:
>I currently have the following command:
>
>find . -name "*\.[CH]" | grep -v /src/menu/
>
>This gives me a list of all files that end in .C or .H but do not have
>the string "/src/menu" in them.
>
>This works, but I'm trying to eliminate the call to grep.  I need a
>regular expression that combines "*\.[CH]" with "-v /src/menu".  I've
>searched for examples on the web and usenet, but I still can't figure
>it out.  How do I do a logical-AND with regular expressions?

*can't*,   as asked.

What you want is simply:

find . (! -path '*/src/menu/*') -a -name '*[CH]'  -print







[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 06:35 AM

On Wed, 21 Apr 2004 at 05:10 GMT, Robert Bonomi wrote:
> In article <53bb806a.0404201611.62515918@posting.google.com>,
> Timur Tabi <nospam_timur@tabi.org> wrote: 
>
> *can't*,   as asked.
>
> What you want is simply:
>
>     find . (! -path '*/src/menu/*') -a -name '*[CH]'  -print

If you need -print, you probably don't have the -path operator
(it's not part of the POSIX spec).

--
Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
rakesh sharma


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 06:35 AM

nospam_timur@tabi.org (Timur Tabi) wrote in message news:

>
> I currently have the following command:
>
> find . -name "*\.[CH]" | grep -v /src/menu/
>
> This gives me a list of all files that end in .C or .H but do not have
> the string "/src/menu" in them.
>
> This works, but I'm trying to eliminate the call to grep.  I need a
> regular expression that combines "*\.[CH]" with "-v /src/menu".  I've
> searched for examples on the web and usenet, but I still can't figure
> it out.  How do I do a logical-AND with regular expressions?
>

if your 'find' has the -path option then you can try this:

find . ! -path /src/menu \( -name '*.[CH]' -o -name '.*.[CH]' \) -ty
pe f -print

Otherwise, you have to make do the -exec processing:

find . -type f \( -name '*.[CH]' -o -name '.*.[CH]' \) -exec sh -c '
case $1 in
*/src/menu*):;;
*) printf "%s\n" "$1";;
esac
' {} {} \;





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 07:34 AM

On 20 Apr 2004 17:11:14 -0700, Timur Tabi
<nospam_timur@tabi.org> wrote:
> I currently have the following command:
>
> find . -name "*\.[CH]" | grep -v /src/menu/
>
> This gives me a list of all files that end in .C or .H but do not have
> the string "/src/menu" in them.
>
> This works, but I'm trying to eliminate the call to grep.  I need a
> regular expression that combines "*\.[CH]" with "-v /src/menu".  I've
> searched for examples on the web and usenet, but I still can't figure
> it out.  How do I do a logical-AND with regular expressions?

With GNU find you can
find . -path "*/src/menu/" -prune -o -name "*.[CH]"
If your find doesn't support -path, you're probably stuck with grep.

--
Giraffe: a ruminant with a view.





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
Charles Demas


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 02:36 PM

In article <ed24e4cf.0404202137.6603535b@posting.google.com>,
rakesh sharma <sharma__r@hotmail.com> wrote:
>nospam_timur@tabi.org (Timur Tabi) wrote in message news:
> 
>
>if your 'find' has the -path option then you can try this:
>
>find . ! -path /src/menu \( -name '*.[CH]' -o -name '.*.[CH]' \) -t
ype f -print
>
>Otherwise, you have to make do the -exec processing:
>
>find . -type f \( -name '*.[CH]' -o -name '.*.[CH]' \) -exec sh -c 
'
>case $1 in
> */src/menu*):;;
> *) printf "%s\n" "$1";;
>esac
>' {} {} \;

or you could exec this:

awk '/\/src\/menu/ {next} {print}'


Chuck Demas

--
Eat Healthy        |   _ _   | Nothing would be done at all,
Stay Fit           |   @ @   | If a man waited to do it so well,
Die Anyway         |    v    | That no one could find fault with it.
demas@theworld.com |  \___/  | http://world.std.com/~cpd





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
rakesh sharma


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 07:36 PM

demas@TheWorld.com (Charles Demas) wrote in message news:

> 


[vbcol=seagreen]
> or you could exec this:
>
> awk '/\/src\/menu/ {next} {print}'
>

But what would the filename be in this case?





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
Charles Demas


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-21-04 10:34 PM

In article <ed24e4cf.0404211003.662cd8b4@posting.google.com>,
rakesh sharma <sharma__r@hotmail.com> wrote:
>demas@TheWorld.com (Charles Demas) wrote in message news:
> 
>
>
> 
>
>But what would the filename be in this case?

The filenames gathered by find.

or you could just pipe the output of the find statement
into the awk line shown.


Chuck Demas

--
Eat Healthy        |   _ _   | Nothing would be done at all,
Stay Fit           |   @ @   | If a man waited to do it so well,
Die Anyway         |    v    | That no one could find fault with it.
demas@theworld.com |  \___/  | http://world.std.com/~cpd





[ Post a follow-up to this message ]



    Re: Regular expression: matching one string and not the other  
rakesh sharma


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-22-04 06:35 AM

demas@TheWorld.com (Charles Demas) wrote in message news:
 
>
> The filenames gathered by find.
>
> or you could just pipe the output of the find statement
> into the awk line shown.
>

I think the OP wanted to know whether the string '/src/menu' is contained
within the filename and NOT within the file.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:06 PM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register