public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* problem using recursive grep (-r option)
@ 2012-08-07 15:08 AngusC
  2012-08-07 15:57 ` Adam Dinwoodie
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: AngusC @ 2012-08-07 15:08 UTC (permalink / raw)
  To: cygwin


If I use the command:

grep -nH -r "my pattern" *.*

I get results back as expected

But if the file pattern is like this:

grep -nH -r "my pattern" *.log

I get no results back (Even though I have a ton of files with this pattern
with .log file extension).

Am I doing something wrong?
-- 
View this message in context: http://old.nabble.com/problem-using-recursive-grep-%28-r-option%29-tp34266659p34266659.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: problem using recursive grep (-r option)
  2012-08-07 15:08 problem using recursive grep (-r option) AngusC
@ 2012-08-07 15:57 ` Adam Dinwoodie
  2012-08-07 16:35 ` marco atzeri
  2012-08-07 18:18 ` Sean Daley
  2 siblings, 0 replies; 14+ messages in thread
From: Adam Dinwoodie @ 2012-08-07 15:57 UTC (permalink / raw)
  To: cygwin

AngusC wrote:
>If I use the command:
>
>grep -nH -r "my pattern" *.*
>
>I get results back as expected
>
>But if the file pattern is like this:
>
>grep -nH -r "my pattern" *.log
>
>I get no results back (Even though I have a ton of files with this pattern
>with .log file extension).
>
>Am I doing something wrong?

Yes.

At a guess, all your .log files are in subdirectories that don't match *.log.
I'd recommend using `find`. Running `man find` will give you some instructions,
as will Google.

That said, you've not given any indication as to why your problem is
specifically relevant to Cygwin. There're plenty of places to get general help
with using Linux tools, but this isn't one of them -- this list is for problems
that are specific to Cygwin. I'd personally recommend heading over to Stack
Overflow or Super User, but there're *many* alternatives for advice on using
generic Linux tools.

If you do want advice from here, I recommend reading and following the
instructions at <http://cygwin.com/problems.html>. Folk here tend to be much
more accommodating if you show you've done the basic research yourself.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 15:08 problem using recursive grep (-r option) AngusC
  2012-08-07 15:57 ` Adam Dinwoodie
@ 2012-08-07 16:35 ` marco atzeri
  2012-08-07 17:19   ` AngusC
                     ` (2 more replies)
  2012-08-07 18:18 ` Sean Daley
  2 siblings, 3 replies; 14+ messages in thread
From: marco atzeri @ 2012-08-07 16:35 UTC (permalink / raw)
  To: cygwin

On 8/7/2012 5:08 PM, AngusC wrote:
>
> If I use the command:
>
> grep -nH -r "my pattern" *.*
>
> I get results back as expected
>
> But if the file pattern is like this:
>
> grep -nH -r "my pattern" *.log
>
> I get no results back (Even though I have a ton of files with this pattern
> with .log file extension).
>
> Am I doing something wrong?
>

in the second case the "-r" is looking for *.log
file or directories and I guess the directory does not match.

Try

find . -name "*.log" -exec grep -nH "my pattern" \{\} \;

Regards
Marco

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 16:35 ` marco atzeri
@ 2012-08-07 17:19   ` AngusC
  2012-08-07 17:32     ` marco atzeri
  2012-08-08  9:11   ` Andy Koppe
  2012-08-08  9:24   ` AngusC
  2 siblings, 1 reply; 14+ messages in thread
From: AngusC @ 2012-08-07 17:19 UTC (permalink / raw)
  To: cygwin


Why would I use find . -name "*.log" -exec grep -nH "my pattern" \{\} \; 
which is much longer to type when I can use grep ... -r ???



marco atzeri-4 wrote:
> 
> On 8/7/2012 5:08 PM, AngusC wrote:
>>
>> If I use the command:
>>
>> grep -nH -r "my pattern" *.*
>>
>> I get results back as expected
>>
>> But if the file pattern is like this:
>>
>> grep -nH -r "my pattern" *.log
>>
>> I get no results back (Even though I have a ton of files with this
>> pattern
>> with .log file extension).
>>
>> Am I doing something wrong?
>>
> 
> in the second case the "-r" is looking for *.log
> file or directories and I guess the directory does not match.
> 
> Try
> 
> find . -name "*.log" -exec grep -nH "my pattern" \{\} \;
> 
> Regards
> Marco
> 
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> 
> 
> 
-- 
View this message in context: http://old.nabble.com/problem-using-recursive-grep-%28-r-option%29-tp34266659p34267373.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 17:19   ` AngusC
@ 2012-08-07 17:32     ` marco atzeri
  0 siblings, 0 replies; 14+ messages in thread
From: marco atzeri @ 2012-08-07 17:32 UTC (permalink / raw)
  To: cygwin

On 8/7/2012 7:15 PM, AngusC wrote:
>

do not top post


> Why would I use find . -name "*.log" -exec grep -nH "my pattern" \{\} \;
> which is much longer to type when I can use grep ... -r ???

because it works ?


>>>
>>> But if the file pattern is like this:
>>>
>>> grep -nH -r "my pattern" *.log
>>>
>>> I get no results back (Even though I have a ton of files with this
>>> pattern
>>> with .log file extension).
>>>

and this not.



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 15:08 problem using recursive grep (-r option) AngusC
  2012-08-07 15:57 ` Adam Dinwoodie
  2012-08-07 16:35 ` marco atzeri
@ 2012-08-07 18:18 ` Sean Daley
  2012-08-08  8:24   ` ping
  2012-08-08  9:18   ` AngusC
  2 siblings, 2 replies; 14+ messages in thread
From: Sean Daley @ 2012-08-07 18:18 UTC (permalink / raw)
  To: cygwin

On Tue, Aug 7, 2012 at 11:08 AM, AngusC <> wrote:
>
> If I use the command:
>
> grep -nH -r "my pattern" *.*
>
> I get results back as expected
>
> But if the file pattern is like this:
>
> grep -nH -r "my pattern" *.log
>
> I get no results back (Even though I have a ton of files with this pattern
> with .log file extension).
>
> Am I doing something wrong?
> --
The first one works because *.* will match everything your current directory,
including sub-directories and it will recurse through each of them.  The
second example will first match anything in your current directory with a .log
extension and try to grep it (if it's a file) or recurse through it if
it's a directory.

What I believe you want to do (at least works on Linux) is
grep -nH -r "my pattern" --include "*.log" .

Sean

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 18:18 ` Sean Daley
@ 2012-08-08  8:24   ` ping
  2012-08-08  9:18   ` AngusC
  1 sibling, 0 replies; 14+ messages in thread
From: ping @ 2012-08-08  8:24 UTC (permalink / raw)
  To: cygwin

On 8/7/2012 1:55 PM, Sean Daley wrote:
> On Tue, Aug 7, 2012 at 11:08 AM, AngusC <> wrote:
>>
>> If I use the command:
>>
>> grep -nH -r "my pattern" *.*
>>
>> I get results back as expected
>>
>> But if the file pattern is like this:
>>
>> grep -nH -r "my pattern" *.log
>>
>> I get no results back (Even though I have a ton of files with this pattern
>> with .log file extension).
>>
>> Am I doing something wrong?
>> --
> The first one works because *.* will match everything your current directory,
> including sub-directories and it will recurse through each of them.  The
> second example will first match anything in your current directory with a .log
> extension and try to grep it (if it's a file) or recurse through it if
> it's a directory.
>
> What I believe you want to do (at least works on Linux) is
> grep -nH -r "my pattern" --include "*.log" .
>
> Sean
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>
I think this is the best answer ever so far.

also it looks for me:
  grep -nHr "pattern" *.*
    equals:
  grep -nHr "pattern" .

I use the latter alot to quickly locate a file per content.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 16:35 ` marco atzeri
  2012-08-07 17:19   ` AngusC
@ 2012-08-08  9:11   ` Andy Koppe
  2012-08-08  9:24   ` AngusC
  2 siblings, 0 replies; 14+ messages in thread
From: Andy Koppe @ 2012-08-08  9:11 UTC (permalink / raw)
  To: cygwin

On 7 August 2012 16:57, marco atzeri wrote:
> On 8/7/2012 5:08 PM, AngusC wrote:
>>
>>
>> If I use the command:
>>
>> grep -nH -r "my pattern" *.*
>>
>> I get results back as expected
>>
>> But if the file pattern is like this:
>>
>> grep -nH -r "my pattern" *.log
>>
>> I get no results back (Even though I have a ton of files with this pattern
>> with .log file extension).
>>
>> Am I doing something wrong?
>>
>
> in the second case the "-r" is looking for *.log
> file or directories and I guess the directory does not match.
>
> Try
>
> find . -name "*.log" -exec grep -nH "my pattern" \{\} \;

Or have a look at grep's --include option.

Andy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 18:18 ` Sean Daley
  2012-08-08  8:24   ` ping
@ 2012-08-08  9:18   ` AngusC
  2012-08-08 10:03     ` marco atzeri
  1 sibling, 1 reply; 14+ messages in thread
From: AngusC @ 2012-08-08  9:18 UTC (permalink / raw)
  To: cygwin


I did try the --include way but in Cygwin it didn't work for some reason.

Neither does

find "." -name "*.log" -exec grep -nH "my pattern" {} \;

or 
find "." -name "*.log" | grep -nH "my pattern"

So struggling about on Cygwin at the moment.




Sean Daley-2 wrote:
> 
> On Tue, Aug 7, 2012 at 11:08 AM, AngusC <> wrote:
>>
>> If I use the command:
>>
>> grep -nH -r "my pattern" *.*
>>
>> I get results back as expected
>>
>> But if the file pattern is like this:
>>
>> grep -nH -r "my pattern" *.log
>>
>> I get no results back (Even though I have a ton of files with this
>> pattern
>> with .log file extension).
>>
>> Am I doing something wrong?
>> --
> The first one works because *.* will match everything your current
> directory,
> including sub-directories and it will recurse through each of them.  The
> second example will first match anything in your current directory with a
> .log
> extension and try to grep it (if it's a file) or recurse through it if
> it's a directory.
> 
> What I believe you want to do (at least works on Linux) is
> grep -nH -r "my pattern" --include "*.log" .
> 
> Sean
> 
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> 
> 
> 
-- 
View this message in context: http://old.nabble.com/problem-using-recursive-grep-%28-r-option%29-tp34266659p34270643.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-07 16:35 ` marco atzeri
  2012-08-07 17:19   ` AngusC
  2012-08-08  9:11   ` Andy Koppe
@ 2012-08-08  9:24   ` AngusC
  2012-08-09  6:58     ` Andrey Repin
  2 siblings, 1 reply; 14+ messages in thread
From: AngusC @ 2012-08-08  9:24 UTC (permalink / raw)
  To: cygwin


This works

find . -name "*.log" | grep -nH -r "my pattern" *.*


marco atzeri-4 wrote:
> 
> On 8/7/2012 5:08 PM, AngusC wrote:
>>
>> If I use the command:
>>
>> grep -nH -r "my pattern" *.*
>>
>> I get results back as expected
>>
>> But if the file pattern is like this:
>>
>> grep -nH -r "my pattern" *.log
>>
>> I get no results back (Even though I have a ton of files with this
>> pattern
>> with .log file extension).
>>
>> Am I doing something wrong?
>>
> 
> in the second case the "-r" is looking for *.log
> file or directories and I guess the directory does not match.
> 
> Try
> 
> find . -name "*.log" -exec grep -nH "my pattern" \{\} \;
> 
> Regards
> Marco
> 
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> 
> 
> 
-- 
View this message in context: http://old.nabble.com/problem-using-recursive-grep-%28-r-option%29-tp34266659p34270681.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-08  9:18   ` AngusC
@ 2012-08-08 10:03     ` marco atzeri
  2012-08-08 16:58       ` Gary Johnson
  0 siblings, 1 reply; 14+ messages in thread
From: marco atzeri @ 2012-08-08 10:03 UTC (permalink / raw)
  To: cygwin

On 8/8/2012 11:11 AM, AngusC wrote:
>
DO NOT TOP POST !

> I did try the --include way but in Cygwin it didn't work for some reason.
>
> Neither does
>
> find "." -name "*.log" -exec grep -nH "my pattern" {} \;

find "." -name "*.log" -exec grep -nH "my pattern" \{\} \;



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-08 10:03     ` marco atzeri
@ 2012-08-08 16:58       ` Gary Johnson
  0 siblings, 0 replies; 14+ messages in thread
From: Gary Johnson @ 2012-08-08 16:58 UTC (permalink / raw)
  To: cygwin

On 2012-08-08, marco atzeri wrote:
> On 8/8/2012 11:11 AM, AngusC wrote:
> >
> DO NOT TOP POST !
> 
> >I did try the --include way but in Cygwin it didn't work for some reason.

Both of these work fine for me in Cygwin (on Windows XP):

    grep -nH -r "my pattern" --include "*.log" .
    grep -nH -r "my pattern" --include=*.log .

> >Neither does
> >
> >find "." -name "*.log" -exec grep -nH "my pattern" {} \;

as does that

> 
> find "." -name "*.log" -exec grep -nH "my pattern" \{\} \;

and that.

The quoting of . and {} is not needed.

Perhaps the real problem is with "my pattern".

Regards,
Gary


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-08  9:24   ` AngusC
@ 2012-08-09  6:58     ` Andrey Repin
  2012-08-09 15:30       ` Larry Hall (Cygwin)
  0 siblings, 1 reply; 14+ messages in thread
From: Andrey Repin @ 2012-08-09  6:58 UTC (permalink / raw)
  To: AngusC, cygwin

Greetings, AngusC!


> This works

> find . -name "*.log" | grep -nH -r "my pattern" *.*

What? This is ridiculous.
Do you read what you write?


--
WBR,
Andrey Repin (anrdaemon@freemail.ru) 09.08.2012, <10:27>

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: problem using recursive grep (-r option)
  2012-08-09  6:58     ` Andrey Repin
@ 2012-08-09 15:30       ` Larry Hall (Cygwin)
  0 siblings, 0 replies; 14+ messages in thread
From: Larry Hall (Cygwin) @ 2012-08-09 15:30 UTC (permalink / raw)
  To: cygwin

On 8/9/2012 2:27 AM, Andrey Repin wrote:
> Greetings, AngusC!
>
>
>> This works
>
>> find . -name "*.log" | grep -nH -r "my pattern" *.*
>
> What? This is ridiculous.
> Do you read what you write?

Indeed.  Can we all agree that this thread has drifted far enough away
from anything Cygwin-specific that it can be termed off-topic now?
Let's let the thread die.

-- 
Larry

_____________________________________________________________________

A: Yes.
 > Q: Are you sure?
 >> A: Because it reverses the logical flow of conversation.
 >>> Q: Why is top posting annoying in email?

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-08-09 15:06 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-07 15:08 problem using recursive grep (-r option) AngusC
2012-08-07 15:57 ` Adam Dinwoodie
2012-08-07 16:35 ` marco atzeri
2012-08-07 17:19   ` AngusC
2012-08-07 17:32     ` marco atzeri
2012-08-08  9:11   ` Andy Koppe
2012-08-08  9:24   ` AngusC
2012-08-09  6:58     ` Andrey Repin
2012-08-09 15:30       ` Larry Hall (Cygwin)
2012-08-07 18:18 ` Sean Daley
2012-08-08  8:24   ` ping
2012-08-08  9:18   ` AngusC
2012-08-08 10:03     ` marco atzeri
2012-08-08 16:58       ` Gary Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).