Jump to content

grep for words


rubing

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.