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

    Join Date
    Nov 2003
    Posts
    701
    Rep Power
    96

    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. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,295
    Rep Power
    9400
    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