converting odt to plaintext en masse

Discuss Programming
Post Reply
Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

converting odt to plaintext en masse

Post by Master of Reality » Mon Nov 05, 2007 10:02 pm

Anyone know a way to convert a directory with a bunch of odt files into plaintext. There is no formatting in the files (other than line breaks).

User avatar
Void Main
Site Admin
Site Admin
Posts: 5715
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Tue Nov 06, 2007 9:20 am

Search Google for "odt2txt". There are a few that pop up and the first one looks very promising. It's a Python script:

http://www.freewisdom.org/projects/pyth ... dt2txt.php

With that command you would do something like:

Code: Select all

$ cd /odtdir
$ for i in *.odt; do odt2txt.py $i > ${i%%odt}txt; done
Otherwise it wouldn't be too difficult to write one. You can extract the content by unzipping the ODT file and then convert it from XML to txt.

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Wed Nov 07, 2007 11:27 am

ah... if only openoffice had more commandline features to do crazy stuff like this.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5715
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Wed Nov 07, 2007 11:52 am

Well you could do it with a OpenOffice macro script as well but I think this way would be easier.

User avatar
Calum
guru
guru
Posts: 1348
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Wed Nov 14, 2007 8:26 am

listen, i am having a different but similar issue with unix2dos

i have it installed and the files i want to change are on a vfat filesystem. It doesn't convert them, presumably because it can't make backup copies of the files (which is why text editors such as gedit complain when you try and save a copy over the top of a text file on a vfat filesystem too, vfat system doesn't allow you to have example.txt~ as a real filename)

Any solution to this which doesn't involve shunting all the files onto a different filesystem? I know there is a dos version of this, and it must work on msdos/vfat filesystems, so in a way, this limitation in the linux version means it is crippled compared with the dos version (how evil of me to put it like that, eh?)

User avatar
Void Main
Site Admin
Site Admin
Posts: 5715
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Wed Nov 14, 2007 9:17 am

That's odd. I don't have those problems on my vfat file system. I can edit files and use unix2dos/dos2unix on them with no problem and no error. Maybe it's a mount option you are using? Unless you're underlying fat file system is not FAT32 and doesn't support long file names.

User avatar
Calum
guru
guru
Posts: 1348
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Thu Nov 15, 2007 7:16 am

it is fat32, and does support long filenames, i definitely get a fairly loquacious error message from gedit when i try to save any text file that exists on a vfat file system, and it says it can't create a backup file, i assumed it was something to do with the filename, and further assumed that was the same problem for unix2dos.

Your reply makes me think it's more than that though, so i'll have a quick google and see what i can find out. thanks!

User avatar
Void Main
Site Admin
Site Admin
Posts: 5715
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Thu Nov 15, 2007 9:21 am

What does your /etc/fstab entry look like for it? What is the output of the command "mount"? Here's what I get for my fat32 file system:
/dev/sda6 on /d type vfat (rw)
Basically it's mounted with default options:
/dev/sda6 /d vfat defaults 0 0
Can you copy and paste the exact errors from each of the programs?

User avatar
Calum
guru
guru
Posts: 1348
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Fri Nov 16, 2007 4:12 pm

here's the error i get when trying to save in gedit on a vfat filesystem.
Image
here are the relevant lines of output from these commands, along with me trying to use unix2dos...

Code: Select all

[calum@harvey ~]$ cat /etc/fstab 
/dev/hda1    /winsux         vfat    defaults,umask=0               0 0 
/dev/sda5    /media/disk     auto    rw,users,defaults,sync,umask=0 0 0 

[calum@harvey winsux]$ mount
/dev/hda1 on /winsux type vfat (rw,umask=0)
/dev/sda5 on /media/disk type vfat (rw,noexec,nosuid,nodev,sync,umask=0)

[calum@harvey winsux]$ unix2dos Traffic*/*txt
unix2dos: converting file Traffic - John Barleycorn Must Die/johnbarleycorn.txt to DOS format ...
unix2dos: problems converting file Traffic - John Barleycorn Must Die/johnbarleycorn.txt
by the way, /winsux doesn't contain a windows operating system, and hasn't for a very long time, it's just i'm still in the habit of keeping a vfat partition on /dev/hda1 just in case. It actually contains a whole lot of mp3 backups of music CDs at the moment. a much more resourceful use of my disk space, in my opinion.

Post Reply