Creating HTML Links with Page Titles using Raw URLs in Linux Shell

Given a plain text list of URLs (for example links in your history) you want to create a list of HTML links which have the same title as the page’s document title. Offcourse, you want to do it with a script!

Example input:

https://www.invision-web.net/

https://www.share-2-web.com/

Example output:

<a target="_blank" href="https://www.invision-web.net/">InVision-Web.net :: Top work at Web Developement and Design - Home</a>
<a target="_blank" href="https://www.share-2-web.com/">Share to Web - The easiest way to share your Web Content</a>

Script usage example: prettylinks.sh

./prettylinks.sh < raw_urls.txt > html_titled_links.txt

You can view or download the script here:

https://invision-web.net/web/sources/prettylinks.sh

Or obtain it from shell:

wget -qO- https://invision-web.net/web/sources/prettylinks.sh > prettylinks.sh
chmod +x prettylinks.sh

prettylinks.sh

#!/bin/bash
# usage: ./prettylinks.sh < raw_urls.txt > html_titled_links.txt
while read line; do
        url=$line
        if [ "" != "$line" ]; then
                tempfile=$(mktemp)
                wget -qO- $url > $tempfile
                title=$(cat $tempfile | grep '<title>' \
					| sed 's/<[^>]\+>//g' | sed 's/^[ \t]*//;s/[ \t]*$//');
                echo -e "<a target=\"_blank\" href=\"$url\">$title</a>";
        fi;
done
Linux Shell / Bash Scripting, Open Source, Tutorials | Posted on July 2, 2013 by .

About Kristijan Burnik

Kristijan Burnik is a Programmer and Web Developer specializing in Server-side and Client-side Technologies and Application Development on Linux Servers and Windows Desktop . Also has experience in Networking, Desktop application development as well as Android mobile application development . Experienced in Programming Languages like Java, C, C++, C#, PHP, Javascript, MySQL and somewhat in other languages like Bash, Perl & Python. Sometimes he works as a Graphical Designer for digital production as well as for printing and advertising. He dedicates his spare time writing Tech Articles on his blog in order to share his work with others, as well as to document his projects for his own use. He's also an Educator & Mentor in field of Algorithms and Programming to young programmers in Zagreb, Croatia.

Leave a Reply