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
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
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
Share on other sites

sorry thorpe.  yes i am just looking to extract the url from the line of interest.

 

It just seems that you already have most of what you want in your pattern.

 

Can we see an example of an entire line and your pattern?

Link to comment
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
Share on other sites

 

:)i recently became a member of this forum 8)

You bumped this two months why?

Welcome to the boards, however....

 

Running around bumping old solved threads is considered bad form on any forum. Please refrain from doing so.

Link to comment
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.