LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-15-2010, 08:00 AM   #1
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Rep: Reputation: 15
Shell script or other method to convert firefox bookmark file to excel


I have a big file of links
I have some entries in this format:
Code:
<A HREF="http://www.....html" ADD_DATE="1271073056" LAST_MODIFIED="1271073061">18010139</A>
others like this
Code:
<a href=http://www....html>02230726</a>
The top ones are just from a firefox bookmark file.

Need to convert them into an excel spreadsheet, preferably
so they are in this format

Code:
   A           B            C
1  CODE       Hyperlink     URL
2  18010139   18010139      http://www....
3  02230726   02230726      http://www....
I realise I can easily create column B from columns A and C in Excel but columnn C does actually have to be a hyperlink if this is done in one script.

Last edited by suse_nerd; 04-15-2010 at 08:02 AM.
 
Old 04-15-2010, 08:03 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by suse_nerd View Post
I have a big file of links
I have some entries in this format:
Code:
<A HREF="http://www.....html" ADD_DATE="1271073056" LAST_MODIFIED="1271073061">18010139</A>
others like this
Code:
<a href=http://www....html>02230726</a>
The top ones are just from a firefox bookmark file.

Need to convert them into an excel spreadsheet, preferably
so they are in this format

Code:
   A           B            C
1  CODE       Hyperlink     URL
2  18010139   18010139      http://www....
3  02230726   02230726      http://www....
I realise I can easily create column B from columns A and C in Excel but columnn C does actually have to be a hyperlink if this is done in one script.
Use Perl, pick an HTML parsing module and pick an Excel writing module (or CSV one). All mentioned categories of modules exist and are well established.
 
Old 04-15-2010, 08:26 AM   #3
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Thankyou for that, unfortunately I do not have time to do this in perl. Can you suggest where I might find this sort of tool online?

By the way this is not homework, but is actual work!

It is my own fault the files are not in the format required, need a quick fix.
 
Old 04-15-2010, 08:36 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Does this file contains these two samples only. or it contains other text as well ?
Can you assure that each line contains one link only ?
Column A and Column B will be same ?
 
Old 04-15-2010, 09:19 AM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Saying you don't have time is just an excuse. Time is never enough for everybody, not just you. Its up to yourself to find the time. No time ? then cut down on your parties, spend 1 or 2 hrs before you sleep to learn etc. after all, its for your work right?

Back to topic, you can use Python. Assuming you are not using later version of firefox which uses json instead

Code:
import re
html=open("bookmarks.html","Ur").read()
html=re.split("</[aA]>",html)
sp=re.compile("<a href=|>",re.I|re.DOTALL|re.M)
for item in html:
    if "<a href" in item.lower():
        chunks=item.split("\n")
        whatiwant=sp.split(chunks[0].strip())
        if whatiwant[0]=="": whatiwant.pop(0)
        try: print whatiwant[0].split()[0],whatiwant[-1]
        except: pass
this only gets the data out from the html. you can use csv module to write csv after that.

Last edited by ghostdog74; 04-15-2010 at 10:19 AM.
 
Old 04-15-2010, 09:23 AM   #6
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
perl -e 'while(<>){ /href="?(.*?)(".*)?>/i; my $url=$1; />(.*)</; my $code = $1; print "$code,$code,$url\n"; }' <file>
 
Old 04-15-2010, 09:28 AM   #7
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
In case this helps, regarding post #5 -- even the shiny new Firefox can/will export your bookmarks as HTML, even though it uses JSON internally. Select Bookmarks -> Organize -> Import/Backup -> Export HTML, and then you could proceed with post #5 if you like (or whatever method, if your chosen method wants to begin with an HTML-formatted file).
 
Old 04-15-2010, 09:33 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by PMP View Post
Code:
perl -e 'while(<>){ /href="?(.*?)(".*)?>/i; my $url=$1; />(.*)</; my $code = $1; print "$code,$code,$url\n"; }' <file>
that doesn't work since you are not on multiline mode and you can't guarantee every anchor tags end on same line. also the -n option simulates "while(<>)"

Last edited by ghostdog74; 04-15-2010 at 10:22 AM.
 
Old 04-15-2010, 11:27 AM   #9
suse_nerd
Member
 
Registered: May 2008
Distribution: SuSe
Posts: 50

Original Poster
Rep: Reputation: 15
Thanks for your responses.

@PMP that works great, thanks!

I now have all the data in an Excel Spreadsheet.
 
Old 04-15-2010, 02:33 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by suse_nerd View Post
Thanks for your responses.

@PMP that works great, thanks!

I now have all the data in an Excel Spreadsheet.
Of course it works - until your input HTML file format changes. HTML is not a line oriented format.

"Programming by coincidence" (c).
 
Old 04-16-2010, 02:34 AM   #11
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Quote:
Originally Posted by ghostdog74 View Post
that doesn't work since you are not on multiline mode and you can't guarantee every anchor tags end on same line. also the -n option simulates "while(<>)"
Agree, but I took the assumptions [Post #4] and posted it based on that assumptions only. Regarding -n that is something habitual



Quote:
Originally Posted by Sergei Steshenko View Post
Of course it works - until your input HTML file format changes. HTML is not a line oriented format.

"Programming by coincidence" (c).

I respect your thoughts, Given the choice I would have gone for a HTML parser to do so

"Programming by assumption"

Last edited by PMP; 04-16-2010 at 02:35 AM.
 
  


Reply

Tags
bookmarks, convert, excel, firefox, openoffice.org, spreadsheet


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bookmark file for mozilla-firefox ekdya Debian 10 09-28-2006 01:01 AM
convert text file to binary excel file ust Linux - General 2 11-23-2004 03:33 AM
Firefox Bookmark Manager - What are bookmark seperator names for? SBing Linux - Software 2 06-21-2004 03:29 AM
Question about Firefox bookmark file Tiyogi Linux - General 4 03-16-2004 11:19 AM
how to convert a text file into shell script meng_en Linux - General 9 10-15-2002 11:46 PM


All times are GMT -5. The time now is 04:52 PM.

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