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:

Example output:

<a target="_blank" href=""> :: Top work at Web Developement and Design - Home</a>
<a target="_blank" href="">Share to Web - The easiest way to share your Web Content</a>

Script usage example:

./ < raw_urls.txt > html_titled_links.txt

You can view or download the script here:

Or obtain it from shell:

wget -qO- >
chmod +x

# usage: ./ < raw_urls.txt > html_titled_links.txt
while read line; do
        if [ "" != "$line" ]; then
                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>";
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