Re: [Regexp] a regexp question

Levent Yilmaz <[email protected]>
Newsgroups gmane.comp.gnu.regexp
Message-ID <[email protected]>
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
>>> [email protected]
>>> http://mail.gnu.org/mailman/listinfo/gnu-regexp-user
>>
>>
>> s
>>
>> _______________________________________________
>> Gnu-regexp-users mailing list
>> [email protected]
>> http://mail.gnu.org/mailman/listinfo/gnu-regexp-users
> 
> 
> _______________________________________________
> Gnu-regexp-users mailing list
> [email protected]
> http://mail.gnu.org/mailman/listinfo/gnu-regexp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.