Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: grep and recursive -r - not working

  1. #1

    Default grep and recursive -r - not working

    works fine on a FAT32 dsk:
    Code:
    fgrep -iRn -C 2 'print' *.txt
    ---also recurses one level and displays all kinds of data
    ---------------------------------------------------------------
    in root / ext4 directory:
    Code:
    fgrep -iRn -C 2 'print' *.* or fgrep -iRn -C 2 'print' *.txt
    ---displays msgs:
    fgrep: *.*: No such file or directory
    and
    fgrep: *.txt: No such file or directory


    I am probably missing something very basic.

    recursive does not seem to work from root directory. Is this (as they used to say) a feeture?

    This is on an 11.2 system, upgraded to 11.3 (ran zypper verify to verify. According to it.. all is well).

    Thnks...

  2. #2

    Default Re: grep and recursive -r - not working

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    I believe this is a feature. You are saying to match *.txt, and I doubt
    you have any directories matching that so then recursion does not happen
    into those directories. A better way to do this, imo, follows:

    find / -type f -iname *.txt | xargs grep -in -C 2 'print'

    Good luck.





    On 08/09/2010 02:06 PM, danperecky wrote:
    >
    > works fine on a FAT32 dsk:
    >
    > Code:
    > --------------------
    > fgrep -iRn -C 2 'print' *.txt
    > --------------------
    >
    >
    > ---also recurses one level and displays all kinds of data
    > ---------------------------------------------------------------
    > in root / ext4 directory:
    >
    > Code:
    > --------------------
    > fgrep -iRn -C 2 'print' *.* or fgrep -iRn -C 2 'print' *.txt
    > --------------------
    >
    >
    > ---displays msgs:
    > fgrep: *.*: No such file or directory
    > and
    > fgrep: *.txt: No such file or directory
    >
    >
    > I am probably missing something very basic.
    >
    > recursive does not seem to work from root directory. Is this (as they
    > used to say) a feeture?
    >
    > This is on an 11.2 system, upgraded to 11.3 (ran zypper verify to
    > verify. According to it.. all is well).
    >
    > Thnks...
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.15 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iQIcBAEBAgAGBQJMYGC/AAoJEF+XTK08PnB5hnAP/jlbovJrJnsGsBsMYpA350Sd
    9M+x9U28wolZ2L18k76H1slQjR64HIpg5qP5PBCqgUVR90cZ2Dpb6//0WKsrCYJL
    u6ThFiMM8R4wN/bU811uuqwZkrxmVGcuj/gdyAoHpVVwmXCrlWsGoveYTF6+BMHy
    PtqeML14vAGlbDEmmIrtmkOTfUZhg2iI5i0tp20EKjY/+0dYwF3tb27WKC+wii4J
    gcEjWwyApyDzJjKhjHK9FZCQ4OlZ47xOxWozCemGrNJIhbCOWe59+bKbBQ0di5NL
    psHuldH22mNiPgZv4lhXFTd+4dHeTxqhVcWzZQb/tUPJyQL1k7ZuOAytopneTwYv
    qL1iC2iHyLqwcXlmweNo/4fy/sV644Uua8i/o0dV6DVKz9b5BYur+d9sO11YsQst
    txMJ4AkERO5qpZFWgf8FUZIew859P9xbi/wqbHPbxzhEK6R/dsvQAmboQQN/gYUt
    H1oV6JQiNHeS82aExUomGV4cvfT+phkIgsa3MriS35Uc3gPRg7cEcXDdsOzmWLFq
    bF/16D69CicX4FdmQ26gEOcxYpH/52DXVYWWCPZJKiBF0WRqGYn+NMm2DWjvKYYx
    Kjg1eAM3vVRLkdSxfEgTqoICk+zGzbGF4v3iP5P5E4E4Egk9ioRvy70KKLOJkElz
    Nrzs711qEXxiG8to/GC3
    =MX1H
    -----END PGP SIGNATURE-----

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    15,607

    Default Re: grep and recursive -r - not working

    How do you think this is functioning?

    Even if one does not know what all the arguments in
    Code:
    fgrep -iRn -C 2 'print' *.* or fgrep -iRn -C 2 'print' *.txt
    should do, the shell comes first and will try to expand *.* and *.text. I assume there is no file in / that answers to that pattern, thus those arguments stay as they are. And then later fgrep gets *.* as an argument and tries to find (literaly) that file. Which does not exist. same for *.text. And it tells you so.

    And in the first case I suppose that the names that match the pattern *.txt are files, not directories. You can walk down the file tree along directories, but not along files.
    Henk van Velden

  4. #4

    Default Re: grep and recursive -r - not working

    ab@novell.com wrote:
    find / -type f -iname *.txt | xargs grep -in -C 2 'print'
    Thanks... it's elegant and works very nicely.

    A quick related question...

    I added
    2> /dev/null
    to direct error msgs to null. This only worked for the 'grep' part, I believe... as error msgs still appeared from 'find':
    find: 'xfn': Permission denied
    Is there a way to redirect these msgs as well?
    My mission to politely ask all bike riders with loud exhausts to make their bikes quieter. Should be easy.

  5. #5

    Default Re: grep and recursive -r - not working

    Henk wrote:
    And in the first case I suppose that the names that match the pattern *.txt are files, not directories. You can walk down the file tree along directories, but not along files.
    I may be off, but I think it's the other way around... files<->directories(?)

    And.. is this a bug?

    Thanks
    My mission to politely ask all bike riders with loud exhausts to make their bikes quieter. Should be easy.

  6. #6
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,941
    Blog Entries
    4

    Default Re: grep and recursive -r - not working

    Quote Originally Posted by danperecky View Post
    I added to direct error msgs to null. This only worked for the 'grep' part, I believe... as error msgs still appeared from 'find':
    Is there a way to redirect these msgs as well?
    Code:
    find / -type f -iname *.txt 2>/dev/null | xargs grep -in -C 2 'print' 2>/dev/null

  7. #7

    Default Re: grep and recursive -r - not working

    Ken_Yap... Works great... thnks.

  8. #8

    Default Re: grep and recursive -r - not working

    So, is this a bug?
    My mission to politely ask all bike riders with loud exhausts to make their bikes quieter. Should be easy.

  9. #9
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,941
    Blog Entries
    4

    Default Re: grep and recursive -r - not working

    Is what a bug?

  10. #10

    Default Re: grep and recursive -r - not working

    Thank you for your help with 'find' and 'grep'. But if grep would recurse from the root '/' directory when specified, none of those workarounds would be necessary... I'm thinking.

    I may have missed it, but AFAIK there is no clause for the -r option in the man pages that state that the grep -r command option will not work from root.
    My mission to politely ask all bike riders with loud exhausts to make their bikes quieter. Should be easy.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •