We have a file called URLs.txt with URLs:
http://www.google.com http://www.reddit.com
We want to create an HTML file with clickable URLs:
Example:
<a href="http://www.google.com">http://www.google.com</a> <a href="http://www.reddit.com">http://www.reddit.com</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> <html> <head> <title>Sitemap</title> </head> <body> <a href="http://www.google.com">http://www.google.com</a> <a href="http://www.reddit.com">http://www.reddit.com</a> </body> </html>