Recursive GREP

  • Gadrin

    Gadrin - 2005-09-08

    can somebody show me how to compose the command line for a recursive grep?

    I've done searches, but I noticed it's not finding all the files in the subdirs below the main one.

    I saw numerous posts on numerous web pages so I don't feel so bad... :)

    this finds the files in the top folder, but misses the many subfolders underneath...

    grep -i -n -r -U -w "message" c:\test\*.wbt

    • Dave Ewart

      Dave Ewart - 2005-09-08

      > grep -i -n -r -U -w "message" c:\test\*.wbt

      The above will only find subfolders, if the subfolders have names such as "subdir1.wbt", "subdir2.wbt", since you're asking for it to match files/dirs ending in 'wbt'.

      Try just

      grep -i -n -r -U -w "message" c:\test\*

      which will return hits on files other than wbt, but will pick up the subdirectories.

    • Rover

      Rover - 2007-05-30


      I am not sure this is correct. I have faced this problem before but resolved it using this:
         grep -R --include=*.wbt "message" *

      This seems to recursive everything and the --include selects the file pattern matching its value.

      However, when I try this with the grep in

      it ignores the --include directive.


    • Johan

      Johan - 2008-01-29

      > grep -i -n -r -U -w "message" c:\test\*.wbt

      I normally use
         grep -lir "message" *.*
      quite simply because using anything other than "*.*" as the last parameter produces the perplexing error message (when using *.sql):
         grep: *.sql: Invalid argument

      That is, unless there aren't any sub folders to search... then it seems to work fine.

      Additionally, it seems the --directory=ACTION (or -d=ACTION for that matter) switch doesn't work at all - I keep getting "grep: unknown directories method" no matter what I substitute for ACTION.

      rover_007, are you sure you're using the version of grep that comes with UnxUtils?  Mine doesn't seem to have the -R or --include options, giving me error messages when I try to use them (it does have -r, which recurses...)


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks