Find the answer to your Linux question:
Results 1 to 3 of 3
How do I find a word in a file? I want to search only files of a certain extension such as .html or .txt. I want to search recursively since ...
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Posts
    7

    How to find a word in all files of type .html (or .txt)

    How do I find a word in a file?
    I want to search only files of a certain extension such as .html or .txt.
    I want to search recursively since the files can be anywhere.

    I tried the following command but it gave an error
    $ grep -r "cell differentiation" *.html
    The error was "*.html: No such file or directory".

    If I leave off the *.html it scans every fracking file on the system.

  2. #2
    Just Joined!
    Join Date
    Mar 2011
    Posts
    4
    Use --include option for grep.
    Code:
    grep -r "cell differentiation" . --include "*.html"

  3. #3
    Linux User
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    262
    Quote Originally Posted by kwatts59 View Post
    How do I find a word in a file?
    I want to search only files of a certain extension such as .html or .txt.
    I want to search recursively since the files can be anywhere.

    I tried the following command but it gave an error
    $ grep -r "cell differentiation" *.html
    The error was "*.html: No such file or directory".

    If I leave off the *.html it scans every fracking file on the system.
    Code:
    find . -type f -name '*.html' -print0 | xargs -0 grep "cell differentiation"

Posting Permissions

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