HELP: searching for text pattern in unix/linux

Discussion in 'OT Technology' started by hoabegrubn, Jan 29, 2005.

  1. hoabegrubn

    hoabegrubn Active Member

    Joined:
    Dec 11, 2001
    Messages:
    2,098
    Likes Received:
    0
    hey yall

    i need some help here. i am a noob at linux/unix. i'm trying to write a shell that will traverse into each directory below the current directory and search for a given text pattern in each file and print out the filename that has the text pattern and also the line that contains the text pattern


    i can use :

    grep -n 'text' ../*.*

    but that just searches the immediate directory before ... i'm tryin to find some help online but nothing yet .. i think i need to get myself a book and read up :o can anyone help me out? :x: :hs:
     
  2. hoabegrubn

    hoabegrubn Active Member

    Joined:
    Dec 11, 2001
    Messages:
    2,098
    Likes Received:
    0
    or maybe i can use:

    find ../ -print | grep -n 'text'

    :confused: :dunno:
     
  3. hoabegrubn

    hoabegrubn Active Member

    Joined:
    Dec 11, 2001
    Messages:
    2,098
    Likes Received:
    0
    ooh i think i got it kinda ..

    find ../* -print | xargs grep -n 'text'

    kinda works :coold:
     
  4. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,454
    Likes Received:
    12
    Hmm, not sure what you're above syntax does, but it should be:

    find .. -print | xargs -i grep -n <text> {}

    To keep the forking down use:

    find .. -xdev -exec grep -n <text> {} \; -exec ls {} \;
     
  5. hoabegrubn

    hoabegrubn Active Member

    Joined:
    Dec 11, 2001
    Messages:
    2,098
    Likes Received:
    0
    :cool: i'll check it out once i get a chance to
     

Share This Page