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

    Join Date
    Nov 2003
    Posts
    702
    Rep Power
    96

    Grep usage issue


    I am trying to find files that contain
    $_COOKIE['teacher_f_name']
    so I go ahead and I issue
    PHP Code:
    grep --i $_COOKIE\['teacher_m_name * 
    but it flags lines that contain
    teacher_m_name
    without the COOKIE part.
    Evan
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    Quote the whole term otherwise the shell will interpret it.
    Code:
    grep -R -i "\$_COOKIE\['teacher_f_name']"
    Because $_COOKIE looks like a variable and so all you pass is just "[teacher_f_name]".
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    702
    Rep Power
    96
    I've tried so many different iterations without any success:
    grep -R -i -q "$_COOKIE['teacher_f_name']" *
    and
    grep -R -i "\$\_COOKIE\[\'teacher_f_name\'\]" *
    and
    grep -R "$_COOKIE[\'teacher_f_name\']" *
    and no results. Can someone help with the grep command to find
    $_COOKIE['teacher_f_name']"
    in a file?
    Evan
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,485
    Rep Power
    1752
    I presume you are trying to find whatever value that $_COOKIE variable holds, as opposed to the literal value?

    You'd need to wrap the variable reference in quotes, to be sure that if the value has spaces or some special characters in you'll be covered.

    If you are only after the files that contain the value then you'll want the -l (ell) flag to return only filenames that have the matching text in. So, assuming you want it to recurse down the directory structure from current directory and be a case-insensitive search then try:

    Code:
    grep -R -i -l "$_COOKIE['teacher_f_name']" *
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    What I posted? I tested that exact command. Worked fine for me.
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    702
    Rep Power
    96
    Hey,
    Not trying to get anyone upset here. This is the command that worked for me
    grep -Ri "\$_COOKIE\[\'teacher_f_name\'\]" *
    It drove me NUTS but thanks to you and your suggestions I got it to work.
    I need this grep to work because I will be able to see if certain generated cookies are used or not.

    THANKS!
    Last edited by epanagio; December 21st, 2013 at 10:23 PM.
    Evan

IMN logo majestic logo threadwatch logo seochat tools logo