[GLLUG] bookmarks.html Reduction Using vim

Chick Tower c.e.tower at gmail.com
Fri Nov 11 15:14:46 EST 2011


If, like me, you export your bookmarks from Firefox to a file for use on 
other computers or with other browsers (as opposed to backing up your 
bookmarks, which I also do to share them), you might be aghast at the 
size of bookmarks.html.  I investigated, and in large part the bloat is 
from the inclusion of extraneous data.  Firefox exports the date links 
were added and the last time they were visited in addition to the "name" 
of the links and the URLs themselves.  To reduce the size of 
bookmarks.html, yet retain it's usefulness, I created a little script to 
strip out the two dates.  I could have used sed, awk, or even 
conventional programming languages, but I already knew this trick with vim.

In the bash script at the end of this message, the -esc right after 
invoking vim is a series of three flags, not a reference to the Esc key. 
  You can look them up in the vim man page.  You can also use the 
command to substitute one string for another in a file, or even to 
perform some other command in vim.  The wq at the end saves the edited 
file and exits vim.  I had to experiment with this command on 
bookmarks.html, as the .* seems to match everything until the very last 
matching characters that follow it on each line, not just the first 
matching characters it finds.  You could also use this as one line on 
the command line rather than put it in a script as I did, but I plan to 
use it frequently and don't want to have to memorize it.  I use it with 
bookmarks.html created by Firefox 3.6.x, so it might not work on the 
current versions of Firefox.  If someone cares to test it out, I would 
appreciate hearing how well it works.

============
#!/bin/bash
vim -esc "%s/ ADD_DATE.*\"//g | wq" $1
-- 

                                Chick


More information about the linux-user mailing list