How do I pull this information out of this file? sed? grep?

Discussion in 'General Linux' started by Fleximous, Sep 30, 2012.

  1. Fleximous

    Fleximous New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    I hope someone can help..

    If I have a file with say the following content:

    cat test
    fjnjsdnfjnsdjfURLHERE
    lmdslfmdsfURLHERE
    kmkmkdmfkkmk4m5k456mk45URLHERE
    wewew

    What would I need to do to just search throught this file and pull out all the URLs?

    So the end result I would just want to output

    URLHERE
    URLHERE
    URLHERE


    I couldnt post actual URLs as I'm too new to the site. But imagine the URL stars with the usual h t t p : / /

    Many thanks,
  2. WeAreGeek

    WeAreGeek Member

    Messages:
    38
    Likes Received:
    5
    Trophy Points:
    8
    Try this:

    Code:
    sed 's/http/\^http/g' [B]YOURFILENAME[/B] | tr -s "^" "\n" | grep http| sed 's/\ .*//g' 

Share This Page