Welcome to the most active Linux Forum on the web.
Go Back > Blogs > linux-related notes
User Name


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Bash conversion of Opera sessions to "netscape standard" bookmarks

Posted 06-11-2014 at 04:34 AM by the dsc

You run it on the session folder (.win files, usually on ~/.opera/sessions/), and it will generate a single html file with all the bookmarks (taken from the last visited URL for any given tab in that session, hence the file/variable "lasturl" -- the session files record some "history", but this isn't being exported/converted here), and coded "subfolders" for each session file, with the filenames as titles. Every time it runs it rewrites this generated html file.

It may be buggy but I don't know of any alternative yet, except the extremely slow manual method of opening each session and bookmarking all tabs. But even then, it seems that Chrome isn't able to import Opera's own html-exported bookmarks. It must follow the "netscape standard" (used by chrome html export/import).

Requires the program "recode", which perhaps would be more properly used by converting a temporary file rather than piped output. But then there would be mixed code and I don't know how to deal with that, so perhaps it's slower than it could be.

It can be somewhat CPU intensive, one may want to add some subsecond sleep somewhere, or leash it with nice or cpulimit.

# This so-called "software" is COMPLETELY UNLICENSED and barely tested. Use at your own risk
# Seriously. You shouldn't go on executing stuff one posts on the internet without analyzing it carefully.

 cat > opera-exported-bookmarks.html<<-netscape-bookmark-header
 <!DOCTYPE NETSCAPE-Bookmark-file-1>
    <!--This is an automatically generated file.
    It will be read and overwritten.
    Do Not Edit! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

for sessionfile in *.win ; do

sessionname="$(echo "$sessionfile" | sed 's|.win||')"

cat >> opera-exported-bookmarks.html<<-folderstart
<DT><H3 ADD_DATE="0" LAST_MODIFIED="0">$sessionname</H3>

for hist in `grep  "history url]" "$sessionfile"` ; do 

[[ -n "$hist" ]] ; then current="$(echo $hist | sed 's|history.*||;s|^\[||')" 

url=$(grep -A 2 "\["$current"history url\]" "$sessionfile" | grep 0=http | sed 's|0=||'  | recode ascii..html ) 

title=$(grep -A 2 "\["$current"history title" "$sessionfile" | grep 0= | sed 's|0=||' | recode ascii..html ) 

if [[ -n "$url" ]] ; then

if [[ -z "$title" ]] ; then echo FAKETITLE ; title="$(echo $url |sed s'|^http://||;s|^www.||;s|\..*||')...$(echo $url | tail -c 20 )"

cat >> opera-exported-bookmarks.html<<-lasturls
<DT><A HREF="$url" ADD_DATE="0">$title</A>


fi ; done 

echo '</DL><p>' >> opera-exported-bookmarks.html 


echo '</DL><p>' >> opera-exported-bookmarks.html
Posted in Uncategorized
Views 1402 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 12:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration