#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    lansing
    Posts
    2
    Rep Power
    0

    Smile using grep to find and not find strings


    I'm trying to search php files in a directory for their include files except those that have the strings "header" or "footer".
    This is what I'm using so far with no luck:

    grep -Ers '((include|require)_once|include|include_files).*[^(footer|header)].*' directory_name

    I guess my question is how do I use the ^ to do a no match on strings. I can't seem to find the right documentation or examples anywhere.
    I'm using GNU grep version 2.4.2...Please help. Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    I would do it in two steps:
    1. find all includes
    2. remove the headers and footers.
    Code:
    grep -Eir . 'include(_files)?|require(_once)?' | grep -viE 'header|footer'
    ... adjust to your needs

    ("grep -v" is find "not")

    hth,
    M.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    lansing
    Posts
    2
    Rep Power
    0

    aahhhh


    brilliant. thanks!

IMN logo majestic logo threadwatch logo seochat tools logo