Issue
I would like to understand how to extract all links (starting with www
and ending with .com
) from a text body such as below. Multiple occurrences may or may not occur per line.
cat body.txt
text more-text url="http://www.link1.com">textblabla textbla=textblabla url="http://www.link2.com">textblabla textblabla=textblabla textblabla
url="http://www.link3.com"> textblabla textblablabla=bla
Desired output:
www.link1.com
www.link2.com
www.link3.com
Solution
Using grep
$ grep -o 'www\.[^.]*\.com' input_file
www.link1.com
www.link2.com
www.link3.com
Answered By - HatLess Answer Checked By - Marilyn (WPSolving Volunteer)