#1
  1. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15

    ls/grep question


    so i can grep some files and find a string like this:

    cat file* | grep something

    however how do i get the file name also?
  2. #2
  3. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    111
    grep string *php

    will get all occurrences of string in all the php files

    grep -ir string *php

    will do the same with case-insensitivity and recursion

    the file names will be provided along with the, er, offending(!) line


    christo
    This is me: http://chris.uk.com
  4. #3
  5. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    111
    oh and.. I just knocked up this one:

    Code:
    grep -ir string *php | cut -f1 -d':' | uniq
    will uniquely list the names of all the php files containing string with case-insensitivity and recursion.

    christo
    This is me: http://chris.uk.com
  6. #4
  7. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    thanks man. i also broke down and looked at the man pages for grep and -H works well also.


IMN logo majestic logo threadwatch logo seochat tools logo