Quantcast
Channel: Linux and Mac Hacks
Viewing all articles
Browse latest Browse all 39

Use grep and regular expressions to find a URL

$
0
0
I spent a lot of time searching through a number of different regular expressions to find a URL in a body of text and finally ended up with this one - make sure you replace somefile.txt with the file you want to search:

grep -oE '\b(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]' somefile.txt

If somebody has a url it fails on, please let me know. 

Viewing all articles
Browse latest Browse all 39

Latest Images

Trending Articles



Latest Images