public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Is grep broken?
@ 2009-07-01 14:30 Peter Humphrey
  2009-07-01 14:34 ` Alan McKinnon
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Peter Humphrey @ 2009-07-01 14:30 UTC (permalink / raw
  To: gentoo-user

Hello list,

Can anyone explain this to me?

$ /bin/grep -r hmenu *html
index.html:                     <div id="hmenu">
master.html:                    <div id="hmenu">
pictures.html:                  <div id="hmenu">

$ /bin/grep -r hmenu pages/*html
pages/community.html:                   <div id="hmenu">
pages/contacts.html:                    <div id="hmenu">
pages/history.html:                     <div id="hmenu">
pages/music.html:                       <div id="hmenu">
pages/news.html:                        <div id="hmenu">
pages/people.html:                      <div id="hmenu">
pages/pictures.html:                    <div id="hmenu">

Grep is clearly disobeying the recursion command. I started noticing this a 
few days ago, and it's making maintenance of this directory hard work.

-- 
Rgds
Peter



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

* Re: [gentoo-user] Is grep broken?
  2009-07-01 14:30 [gentoo-user] Is grep broken? Peter Humphrey
@ 2009-07-01 14:34 ` Alan McKinnon
  2009-07-01 14:37 ` Patrick Holthaus
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Alan McKinnon @ 2009-07-01 14:34 UTC (permalink / raw
  To: gentoo-user

On Wednesday 01 July 2009 16:30:26 Peter Humphrey wrote:
> Hello list,
>
> Can anyone explain this to me?
>
> $ /bin/grep -r hmenu *html
> index.html:                     <div id="hmenu">
> master.html:                    <div id="hmenu">
> pictures.html:                  <div id="hmenu">
>
> $ /bin/grep -r hmenu pages/*html
> pages/community.html:                   <div id="hmenu">
> pages/contacts.html:                    <div id="hmenu">
> pages/history.html:                     <div id="hmenu">
> pages/music.html:                       <div id="hmenu">
> pages/news.html:                        <div id="hmenu">
> pages/people.html:                      <div id="hmenu">
> pages/pictures.html:                    <div id="hmenu">
>
> Grep is clearly disobeying the recursion command. I started noticing this a
> few days ago, and it's making maintenance of this directory hard work.

You equally clearly do not understand how recursion works. You told it to grep 
through all the html files starting from pages/ and it did so.

You did not tell it to start from pages/.. so why do you think it should do 
so?

-- 
alan dot mckinnon at gmail dot com



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

* Re: [gentoo-user] Is grep broken?
  2009-07-01 14:30 [gentoo-user] Is grep broken? Peter Humphrey
  2009-07-01 14:34 ` Alan McKinnon
@ 2009-07-01 14:37 ` Patrick Holthaus
  2009-07-01 14:47   ` Peter Humphrey
  2009-07-01 15:57 ` [gentoo-user] " Grant Edwards
  2009-07-02  7:23 ` [gentoo-user] " Carlos
  3 siblings, 1 reply; 10+ messages in thread
From: Patrick Holthaus @ 2009-07-01 14:37 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1233 bytes --]

On Wednesday 01 July 2009 16:30:26 Peter Humphrey wrote:
> Hello list,
>
> Can anyone explain this to me?
>
> $ /bin/grep -r hmenu *html
> index.html:                     <div id="hmenu">
> master.html:                    <div id="hmenu">
> pictures.html:                  <div id="hmenu">

The star is evaluated /before/ grep is executed. Therefore, only files that are 
ending with html are searched recursively. If you had placed the files in a 
directory called blablahtml, then grep would have searched there.

> $ /bin/grep -r hmenu pages/*html
> pages/community.html:                   <div id="hmenu">
> pages/contacts.html:                    <div id="hmenu">
> pages/history.html:                     <div id="hmenu">
> pages/music.html:                       <div id="hmenu">
> pages/news.html:                        <div id="hmenu">
> pages/people.html:                      <div id="hmenu">
> pages/pictures.html:                    <div id="hmenu">
>
> Grep is clearly disobeying the recursion command. I started noticing this a
> few days ago, and it's making maintenance of this directory hard work.

No, you just did not tell it to search in the the directory pages. :)

HTH
Patrick


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

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

* Re: [gentoo-user] Is grep broken?
  2009-07-01 14:37 ` Patrick Holthaus
@ 2009-07-01 14:47   ` Peter Humphrey
  2009-07-01 14:56     ` Neil Bothwick
  2009-07-01 18:03     ` Keith Dart
  0 siblings, 2 replies; 10+ messages in thread
From: Peter Humphrey @ 2009-07-01 14:47 UTC (permalink / raw
  To: gentoo-user

On Wednesday 01 July 2009 15:37:15 Patrick Holthaus wrote:

> No, you just did not tell it to search in the the directory pages. :)

I'm sure it used to work the way I want it to. I think I see insanity 
looming...

-- 
Rgds
Peter



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

* Re: [gentoo-user] Is grep broken?
  2009-07-01 14:47   ` Peter Humphrey
@ 2009-07-01 14:56     ` Neil Bothwick
  2009-07-01 18:03     ` Keith Dart
  1 sibling, 0 replies; 10+ messages in thread
From: Neil Bothwick @ 2009-07-01 14:56 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

On Wed, 1 Jul 2009 15:47:52 +0100, Peter Humphrey wrote:

> > No, you just did not tell it to search in the the directory
> > pages. :)  
> 
> I'm sure it used to work the way I want it to. I think I see insanity 
> looming...

It does work the way you want it to, just not the way you told it to :)


-- 
Neil Bothwick

Multitasking: Reading in the bathroom.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* [gentoo-user]  Re: Is grep broken?
  2009-07-01 14:30 [gentoo-user] Is grep broken? Peter Humphrey
  2009-07-01 14:34 ` Alan McKinnon
  2009-07-01 14:37 ` Patrick Holthaus
@ 2009-07-01 15:57 ` Grant Edwards
  2009-07-02  7:23 ` [gentoo-user] " Carlos
  3 siblings, 0 replies; 10+ messages in thread
From: Grant Edwards @ 2009-07-01 15:57 UTC (permalink / raw
  To: gentoo-user

On 2009-07-01, Peter Humphrey <peter@humphrey.ukfsn.org> wrote:

> Can anyone explain this to me?
>
> $ /bin/grep -r hmenu *html
> index.html:                     <div id="hmenu">
> master.html:                    <div id="hmenu">
> pictures.html:                  <div id="hmenu">

The shell expands *html to a list of html files in the current
directory.  IOW, you explicitly gave grep a list of html files
to search.  The -r flag does nothing in that case.

You appear to want to search all files underneath the current
directory who's name matches the shell glob pattern "*html".
If that's the case, then what you meant to say was:

  find . -name '*html' | xargs grep hmenu

> $ /bin/grep -r hmenu pages/*html
> pages/community.html:                   <div id="hmenu">
> pages/contacts.html:                    <div id="hmenu">
> pages/history.html:                     <div id="hmenu">
> pages/music.html:                       <div id="hmenu">
> pages/news.html:                        <div id="hmenu">
> pages/people.html:                      <div id="hmenu">
> pages/pictures.html:                    <div id="hmenu">
>
> Grep is clearly disobeying the recursion command. I started noticing this a 
> few days ago, and it's making maintenance of this directory hard work.

Again, you gave grep an explicit list of files to search, so
the -r option doesn't do anything.  In this case, it's not
obvious what you intend, so I'll refrain from guessing.

-- 
Grant Edwards                   grante             Yow! I want to kill
                                  at               everyone here with a cute
                               visi.com            colorful Hydrogen Bomb!!




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

* Re: [gentoo-user] Is grep broken?
  2009-07-01 14:47   ` Peter Humphrey
  2009-07-01 14:56     ` Neil Bothwick
@ 2009-07-01 18:03     ` Keith Dart
  2009-07-01 23:41       ` Peter Humphrey
  1 sibling, 1 reply; 10+ messages in thread
From: Keith Dart @ 2009-07-01 18:03 UTC (permalink / raw
  To: gentoo-user

On Wed, 1 Jul 2009 15:47:52 +0100
Peter Humphrey <peter@humphrey.ukfsn.org> wrote:

> I'm sure it used to work the way I want it to. I think I see insanity 
> looming...

On a side note, you might also want to investigate "sgrep", since
you're grepping inside html files.



-- 
-- --------------------
Keith Dart
<keith@dartworks.biz>
=======================



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

* Re: [gentoo-user] Is grep broken?
  2009-07-01 18:03     ` Keith Dart
@ 2009-07-01 23:41       ` Peter Humphrey
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Humphrey @ 2009-07-01 23:41 UTC (permalink / raw
  To: gentoo-user

On Wednesday 01 July 2009 19:03:34 Keith Dart wrote:
> On Wed, 1 Jul 2009 15:47:52 +0100
>
> Peter Humphrey <peter@humphrey.ukfsn.org> wrote:
> > I'm sure it used to work the way I want it to. I think I see insanity
> > looming...
>
> On a side note, you might also want to investigate "sgrep", since
> you're grepping inside html files.

Thanks for the hint. I'm installing it now. Man grep didn't mention it in 
the "see also" section. Apropos didn't mention it either, since it wasn't 
installed at the time  :-(

-- 
Rgds
Peter



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

* Re: [gentoo-user] Is grep broken?
  2009-07-01 14:30 [gentoo-user] Is grep broken? Peter Humphrey
                   ` (2 preceding siblings ...)
  2009-07-01 15:57 ` [gentoo-user] " Grant Edwards
@ 2009-07-02  7:23 ` Carlos
  2009-07-02 13:36   ` Peter Humphrey
  3 siblings, 1 reply; 10+ messages in thread
From: Carlos @ 2009-07-02  7:23 UTC (permalink / raw
  To: gentoo-user

Peter Humphrey a écrit :
> Hello list,
> 
> Can anyone explain this to me?
> 
> $ /bin/grep -r hmenu *html
> index.html:                     <div id="hmenu">
> master.html:                    <div id="hmenu">
> pictures.html:                  <div id="hmenu">
> 
> $ /bin/grep -r hmenu pages/*html
> pages/community.html:                   <div id="hmenu">
> pages/contacts.html:                    <div id="hmenu">
> pages/history.html:                     <div id="hmenu">
> pages/music.html:                       <div id="hmenu">
> pages/news.html:                        <div id="hmenu">
> pages/people.html:                      <div id="hmenu">
> pages/pictures.html:                    <div id="hmenu">
> 
> Grep is clearly disobeying the recursion command. I started noticing this a 
> few days ago, and it's making maintenance of this directory hard work.
> 

As other have pointed out, the behaviour of grep is correct in the 
examples above.

You could use the --include directive :

grep -r --include=*html hmenu .

Basically, this tells grep to recursive look for hmenu in any files that 
include *html starting from the current directory (* would be equally 
fine if you didn't want to search in 'hidden' dot directories).

Regards,
Carlos



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

* Re: [gentoo-user] Is grep broken?
  2009-07-02  7:23 ` [gentoo-user] " Carlos
@ 2009-07-02 13:36   ` Peter Humphrey
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Humphrey @ 2009-07-02 13:36 UTC (permalink / raw
  To: gentoo-user

On Thursday 02 July 2009 08:23:19 Carlos wrote:

> You could use the --include directive :
>
> grep -r --include=*html hmenu .

Nice idea - thanks.

-- 
Rgds
Peter



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

end of thread, other threads:[~2009-07-02 13:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01 14:30 [gentoo-user] Is grep broken? Peter Humphrey
2009-07-01 14:34 ` Alan McKinnon
2009-07-01 14:37 ` Patrick Holthaus
2009-07-01 14:47   ` Peter Humphrey
2009-07-01 14:56     ` Neil Bothwick
2009-07-01 18:03     ` Keith Dart
2009-07-01 23:41       ` Peter Humphrey
2009-07-01 15:57 ` [gentoo-user] " Grant Edwards
2009-07-02  7:23 ` [gentoo-user] " Carlos
2009-07-02 13:36   ` Peter Humphrey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox