Linux: Convert a text file with URLs to a HTML file with clickable links

We have a file called URLs.txt with URLs:

We want to create an HTML file with clickable URLs:


<a href=""></a>
<a href=""></a>

Use perl to make the URL’s clickable:

$ perl -p -e 's/(.*)/<a href="1" target="_blank">1</a><br>/' urls.txt > urls.html

Now let’s complete the HTML file:

Add the HTML, head, title, and body tags:

$ sed -i '1i <!DOCTYPE html><html><head><title>Sitemap</title></head><body>' urls.html

Add the closing tags at the end of the HTML file:

$ echo "</body></html>" >> urls.html

Resulting file:

<!DOCTYPE html>
        <a href=""></a>
        <a href=""></a>