Jump to content

Recommended Posts

I am using grep to try and find a url in a text file.  typically i only know a single pattern in the url (e.g. 'tresure.com')

 

 

So, Grep does a  great job of finding the line which contains the pattern (e.g.  'come to our site: www.buried-treasure.com')  However, I would like to extract/parse just the url. from this line, that grep is detecting.

Link to comment
https://forums.phpfreaks.com/topic/118536-grep-for-words/
Share on other sites

grep treasure.com urls | sed -r -e "s/.*?(www.*treasure.com).*/\1/g"

 

This is buggy, though. It only works if there is no http(s):// prefixing the URL, and only if there is a www in front of it. If someone can find a way to fix it, please do - I have trouble with multiple zero-or-one expressions.

Link to comment
https://forums.phpfreaks.com/topic/118536-grep-for-words/#findComment-610412
Share on other sites

sorry thorpe.  yes i am just looking to extract the url from the line of interest.  I think I can work with what you wrote here. 

 

using sed is also seems a good idea, but would prefer quick and dirty since i've been told it has a steep learning curve.

 

thx all!

Link to comment
https://forums.phpfreaks.com/topic/118536-grep-for-words/#findComment-610844
Share on other sites

  • 2 months later...

Hello  :);

 

Please try this out

--------

cat file_name | grep key_word > file_name; cat file_name

--------

8)

 

 

I am using grep to try and find a url in a text file.  typically i only know a single pattern in the url (e.g. 'tresure.com')

 

 

So, Grep does a  great job of finding the line which contains the pattern (e.g.  'come to our site: www.buried-treasure.com')  However, I would like to extract/parse just the url. from this line, that grep is detecting.

Link to comment
https://forums.phpfreaks.com/topic/118536-grep-for-words/#findComment-663638
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.