#1
  1. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    694
    Rep Power
    95

    Specifying files to act upon in grep


    I use the following command:
    grep -R "dperson_bridge" *.php
    because I want to search recursively the contents of all .php files containing the phrase "dperson_bridge" and it returns nothing.
    Then I use the following command:
    grep -R "dperson_bridge" *
    and I receive the kind of output I expect to receive.
    Why doesn't the *.php work? I don;t want grep to look into .css or .js files.

    Thanks,
    Evan
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    Because the shell expands wildcards, not grep. As far as grep is concerned you passed it all the filenames matching the pattern ./*.php (ie, all .php files in the current directory).

    There might be an easier way but I use
    Code:
    find -type f -name '*.php' -execdir grep "dperson_bridge" '{}' \;
    (find all *.php files and execute "grep dperson_bridge file" on each)

IMN logo majestic logo threadwatch logo seochat tools logo