Results 1 to 5 of 5

Thread: Finding files

  1. #1
    Join Date
    Aug 2006
    Beans
    445

    Finding files

    I have a bunch of sub-folders which each contain an *.html file.

    I need to, from the parent folder find each (.html) file which contains a 'text string'
    .
    There are endless command line expressions on the 'net which purport to perform this task (using find, or grep, or egrep) but I am unable to find one that works.

    Why that is I have to say is a bit of a mystery.

    However if anyone would be prepared to proffer a command I'd much appreciate it.

    TIA.

  2. #2
    Join Date
    Dec 2006
    Beans
    7,349

    Re: Finding files

    Something like this might work:

    Code:
    find . -iname '*.html' | xargs grep -li 'text string'
    You think that's air you're breathing now?

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Finding files

    Well, it might help if you told us what the 'text string' is (in case there's something unusual about it - special characters perhaps?) and some of the things you've tried? Anyhow here are some other things you can try

    Simplest - will find instances of 'text string' in any non-binary files (regardless of extension):
    Code:
    grep -Ilr 'text string' /path/to/parent/
    Old school (find files with .htm / .html extension (case insensitive) and grep for 'text string' in each non-binary one):
    Code:
    find tests -iname '*.htm?' -exec grep -Il 'text string' {} +
    Using a recursive shell glob
    Code:
    shopt -s globstar
    
    grep -Il 'text string' /path/to/parent/**/*.htm?
    Add a lower-case -i to the greps if you want the actual 'text string' match to be case-insensitive.

  4. #4
    Join Date
    Aug 2006
    Beans
    445

    Re: Finding files

    Code:
    find . -iname '*.html' | xargs grep -li 'text string'
    worked just fine. Thanks so much.

  5. #5
    Join Date
    Dec 2006
    Beans
    7,349

    Re: Finding files

    Quote Originally Posted by Langstracht View Post
    worked just fine. Thanks so much.
    My pleasure .
    You think that's air you're breathing now?

Bookmarks

Posting Permissions

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