I have a document full of URL's that I need to turn into hyperlinks. I have no clue where to begin.

My file looks like this but longer:


And I need it to look like this:

 <a href="http://somesite1.html">http://somesite1.html</a>
 <a href="http://somesiteAD.html">http://somesiteAD.html</a>

Recommendations on how to accomplish this?

  • sed -e 's|.*|<a href="&">&</a>|' Apr 21 '19 at 16:42
  • @RakeshSharma Thank you, that was a huge help and it resolved my problem. My new line reads: grep -lr -Fiw 'KeyWord' * | sed -e 's|.*|<li><a href="http://&">&</a></li>|' >> temp.html
    – David
    Apr 21 '19 at 17:48

If your file only contains lines with URLs:

awk '{print "<a href=\""$1"\">"$1"</a>"}' <urls >hyperlinks

This regex might be helpful:

 s/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/<a href="$1">$1</a>/g

But I advise you to look online yourself for more regexes that match URLs, for your specific case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.