gnu-regexp-users
[Top][All Lists]
Advanced

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

Re: [Regexp] a regexp question


From: Levent Yilmaz
Subject: Re: [Regexp] a regexp question
Date: Fri, 07 May 2004 15:09:26 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 MultiZilla/1.6.3.1d

Thanks for the thinking Thomas!

Yes I have a unix like environment; cygwin, inparticular. And you wouldn't guess how many workarounds I tried for this problem :) And unfortunately what you recommended here is one of the first things that I have tried that did not work.

If you give it a second thought it does not work for more general examples, since all lines without 'puppy.*kitty' are not the lines with kitty. That is,

grep -v "puppy.*kitty" *

Also matches a line such as

no pets allowed :)

But I want a line that contains kitty. Actually, FYI, what I needed is to make grep return the name of the files that contain one or more of such lines (no puppy but kitty lines). Well, I tried many things (with and without regexp) and this is the most decent solution I could get:

(in pseudo commands)
find all <kitty>s and feed the pipe with lines in the form
        <filename: the line that has kitty> |
drop the lines with <puppy.*kitty> |
remove everything but the <filename>s |
remove multiple occurances of the <filename>s

(in real unix commands)
grep -i "kitty" * | \                         
grep -iv ":.*puppy.*kitty" | \
sed 's/:.*//' | \
uniq


Well this does the job. But is barely useful as things get complex. So I really need an elegant regexp to takes care of this.


FYI, the actual reason why I need such a thing is to find in a list of source files(FORTRAN), all occurances of a variable other than where it is declared.

Thank you and best of my greetings!
-Levent


Hartwig, Thomas wrote:
Forget my second email, this was a silly one. Of course you could do something like grep -v "puppy.*kitty" always without sed, but that is not a fine regex of course.

Thomas

Hartwig, Thomas wrote:

If you have a sort of unix this one could help you:

sed 's/puppy.*kitty/§§§/' | grep -v "§§§"

§§§ is just a sample.

Thomas

Levent Yilmaz wrote:

Hello,

It sounded like a very simple problem but I couldn't come up with a solution. I was trying to do this with Basic Regexp in grep:

Find all lines which contain the word 'kitty'. But only those lines that do not have 'puppy' somewhere before 'kitty'. For instance:

my kitty is very cute
but puppy is cuter than kitty

What regular expression stands for the first line but not the second? Note that the other way is very easy, that is the lines with 'puppy' followed by 'kitty': puppy.*kitty

thank you so very much!
-Levent.


PS: What is all this spam on the list by the way?



_______________________________________________
Gnu-regexp-users mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/gnu-regexp-user


s

_______________________________________________
Gnu-regexp-users mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/gnu-regexp-users


_______________________________________________
Gnu-regexp-users mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/gnu-regexp-users





reply via email to

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