Showing posts with label import. Show all posts
Showing posts with label import. Show all posts

Tuesday, April 19, 2011

Windows 7: Converting Old Outlook Express DBX Files

I was running Windows 7.  I had some files with a .dbx extension from Outlook Express (OE) in Windows XP.  There was a separate DBX file for the Inbox, the Outbox, and every other folder I had used in OE.  OE did not come with Win7, and I heard it would not even run on Win7 if I did get a copy of it from somewhere.  This is a brief summary of how I extracted emails from those DBX files.

I had two different kinds of OE DBX files, and I had to use both of the following approaches to get the files out of all of them.  Each approach had its advantages.

First Approach:  DBXConvert

There were many Win7 utilities for sale that would apparently extract individual emails and newsgroup posts from old OE DBX files.  I finally found a freeware solution, DBXConv.zip, available for download from the bottom of a German webpage.  I unzipped and double-clicked the resulting portable DBXConvert.exe (I think it was just dbxconv.exe before I renamed it), but all I saw was the brief flash of a Win7 DOS command box.  This told me that it was doing something in DOS and was then terminating, all too quickly for me to see.

To see what was happening, I wanted to run DBXConvert from a DOS box.  To do this, I used an option I had previously installed using Ultimate Windows Tweaker (UWT).  The option in question was in the Additional Tweaks section of UWT.  This option added an "Open Command Window Here" context menu (i.e., right-click) option in Windows Explorer.  In other words, in Windows Explorer I went to the folder where I had saved DBXConvert.exe, right-clicked on that folder, and opened a command window there.

In the DOS box, I typed DIR to see whatever files were in there, and to run the executable one I just typed its name (e.g., DBXConv.exe) and hit Enter.  Now I saw that DBXConv needed me to specify additional instructions before it would run.  To see the options, as with any DOS command, I typed "dbxconv /?"  Using what I learned from that, I typed "dbxconv -eml [filename]."  I am not sure exactly how I typed the filename, but it worked.  I think I typed something like "dbxconv -eml OutputFile," and that's where the individual messages from the DBX file went.

Second Approach:  Windows Live

If memory serves, I downloaded and installed Windows Live Mail 2011 (WLM) and then found that it would not retrieve newsgroup posts from DBX files, and that's why I went with the DBXConvert approach for some of the DBX files.  The WLM approach did not give me individual EML files that I would then have to import into my email program or convert in an additional step.  Instead, the emails and posts went (or at least I moved them into) my Hotmail account, which I viewed on Thunderbird and then was able to export as individual EMLs.

Friday, March 18, 2011

Thunderbird for Windows: Transition from Portable to Desktop; Duplicate Email Remover

I was using Thunderbird Portable 3.1.4 in Windows 7.  I wanted to use an add-on (Remove Duplicate Messages (Alternate) 0.3.6) to delete duplicate email messages.  I got the impression that it wouldn't run on the portable version.  I had been thinking about switching to the desktop version of Thunderbird anyway, and now seemed like the time.  To figure out how to transition from portable to installed versions of Thunderbird, I ran a search and found advice that seemed on point.  I did not precisely track all of the steps I took in this process, but the following is a pretty close approximation.

I started by installing regular (i.e., not portable) Thunderbird.  I think I created an email account at that point.  This generated C:\Users\Administrator\AppData\Roaming\Thunderbird\Profiles\f0xqaflh.default.  (The f0xqaflh part was randomly generated -- other installations would have a different ????????.default file.)  I closed Thunderbird and moved C:\Users\Administrator\AppData\Roaming\Thunderbird\Profiles\f0xqaflh.default to D:\Thunderbird\Profiles\f0xqaflh.default.  I put it on D so that it would be saved in case of Windows reinstallation.

Then I went to Start > Run > "thunderbird.exe -ProfileManager."  In Profile Manager, I clicked on Create Profile > Next > Choose Folder and pointed to D:\Thunderbird\Profiles.  I exited Profile Manager and moved the contents of ThunderbirdPortable\Data\profile (i.e., just the profile subfolder) to D:\Thunderbird\Profiles.  I clicked on my Start Menu shortcut for Thunderbird (not portable).  It ran, and it seemed that all of my emails were there.  I deleted the folder containing the portable version.

I hoped this was all I needed.  Now it was time to try to delete duplicate emails.  I installed the duplicate email remover add-on (Tools > Add-ons > Extensions tab > Install) and ran it (Tools > Remove Duplicates).  It wouldn't check my archive folder until I turned off the Skip Special Folders option (Tools > Add-ons > Extensions tab > Options > Message Comparison tab).  At first, I used the default comparison criteria in that same tab:  Author, Recipients, CC List, Message ID, Send Time, Size, Body, and Subject.  This did not identify too many duplicates, but it appeared they were exact duplicates, so I could delete them all without much manual comparison.  I ran another search, without the Message ID criterion, and yet another, without the Size comparison.  The former likewise seemed not to require much manual comparison; the latter did.  In other words, the final comparison criteria (Author, Recipients, CC List, Send Time, Subject) produced many alleged duplicates, some of which were of very different size.

The add-on did not allow me to open individual emails (via double-click or right-click), to see why two emails bearing the same subject, date, time, etc. would be so radically different in size, so I had to do a lot of manual toggling back and forth between the duplicate remover and Thunderbird, and then searching for individual items in T-bird, to check emails one by one.  In this regard, it was not like DoubleKiller, which I had found to be an excellent duplicate file finder.  But the manual selection process was similar:  check or uncheck the desired item under the "Keep?" column.  Both of these programs would probably have been easier to use if it had been possible to select or deselect items by clicking anywhere on the line, rather than having to mouse over to precisely the checkbox spot each time.

The add-on did allow arrow-key and spacebar navigation and selection.  Playing with this, I eventually discovered that the Enter key would open T-bird to one of the identified duplicate messages, but in that case the comparison window disappeared and I was back in Thunderbird, leaving me to wonder why I was now seeing only one of the duplicates.  Then I realized, oops, hitting the spacebar had not actually opened the selected duplicate; it had gone ahead and run the deletion.  Well, I hoped those 700 messages really were duplicates.  I had been verging toward just saying to hell with the time-consuming and awkward manual comparison process anyway; I just wasn't quite ready for this to happen.  I looked in Thunderbird's Trash folder and realized that I had not emptied the trash before running the duplicate checker (another ideal feature for the duplicate checker), so now I would have to restore not just the 700 messages that I had apparently just deleted, without an "Are you sure?" message, but would also have to restore about 700 other messages that were apparently in the Trash previously, since I was now seeing a total of 1400 messages there.  As I looked at the Trash, I found myself wondering, actually, what was wrong with those 700 other messages.  They didn't seem to be messages that I would have wanted to delete, unless they too were duplicates.  I decided to move the whole lot of them to the archive folder that I had been dup-checking.  At this point, needless to say, I was beginning to fear that I might just be turning my whole email archive into a giant hash.  I started back through a sequence of dup-checks, beginning with the most conservative (i.e., with the most comparison criteria checked), but of course this time I had no patience for checking individual items.  Instead, I just dreamt of an update that would actually display large thumbnails of alleged duplicates, right there in the add-on.

The column headings in the dup-check results window permitted sorting in ascending or descending order.  At first, I thought that feature was not working for some criteria.  Then I figured out that it was meant to sort only within a comparison.  For example, if Size was not a comparison criterion, it would not be in boldface in the top row, and then clicking on it would sort alleged duplicates according to size; but if Size was a comparison criterion, it would be bolded, and then clicking on that heading in the top row would do nothing, since in that case all duplicates within a set would be identical by definition.  It would have been helpful if selected comparison criteria headings had enabled a sorting of all pairs.  That is, if I was comparing by Send Time, I wanted to be able to show the earliest ones (i.e., the pairs of allegedly time-identical messages) first, so that I wouldn't have to do so much jumping-around when I toggled to Thunderbird for a manual comparison.

After running the several comparisons mentioned above, I tried running one with only the Send Time and Subject criteria checked.  This revealed some apparent duplicates whose only difference was that for some reason one item in a pair would be enclosed in quotation marks (e.g., a message from "Joe") while the other would not (e.g., a message from Joe).

That was the end of my use of the add-on at this point.  I returned to finish this post several hours after completing these processes.  It appeared, at that point, that the transition to desktop Thunderbird and the use of the add-on to delete duplicate emails were both successful.

Tuesday, August 31, 2010

Exporting from Thunderbird, Importing into Thunderbird

I was using Thunderbird as my e-mail program in Ubuntu.  I decided to switch to using Thunderbird 3.1 for Windows as my e-mail program.  It seemed, at this writing, that most people who were transitioning to Thunderbird were going toward Ubuntu, not away from it.  So in this post I am writing up some things that I had to figure out along the way.

I decided to switch to Thunderbird for Windows because I was planning to keep Ubuntu as my underlying operating system, but to focus my applications on Windows XP, which I would be running in a virtual machine in VMware.  This arrangement, I found, gave me dual-boot advantages without having to reboot.

I was particularly interested in using the portable version of Thunderbird as my Windows XP e-mail application.  This would enable me to take my e-mail and my address book with me on a USB flash drive.  The discussion of Thunderbird for Windows in this post relates specifically to the portable version.

After setting up Thunderbird Portable on a Windows computer and making a backup copy, I went into Ubuntu and simply copied over my data.  I found the relevant data in Nautilus (i.e., Ubuntu's File Browser, the equivalent of Windows Explorer), in this location:  Home Folder / .thunderbird / 6abstqrst.default.  (The 6abstqrst part of that name was apparently generated at random, and as such would have a different name in other installations.  Point is, it's the "default" folder.)

I copied that entire default folder to a USB jump drive and compared its subfolders, item by item, to those on the computer where I had installed Thunderbird Portable.  (Of course, I did these and other folder manipulations (below) while Thunderbird was *not* running.)  The comparable e-mail account data seemed especially to be located under the Data\profile\Mail folder.  Thunderbird's Address Book seemed to be in Data\profile\abook.mab.  The Address Book copied and worked without any problem.  The following discussion focuses on problems in getting the e-mail accounts to work correctly.

The simple process of copying e-mail accounts over seemed to work well enough.  I copied all of the folders from Ubuntu via my jump drive to the corresponding Thunderbird folders on the Windows machine.  I kept backups and did this rather painstakingly.  After replacing the contents of one subfolder in Thunderbird Portable with the contents brought over from Thunderbird for Linux, I would start up Thunderbird Portable and make sure that it still seemed to be functioning OK.  Through this process, I ended up with a Thunderbird Portable setup where the desired e-mail accounts did exist.  This may have been helped by the decision to run Thunderbird's Tools > Import option, which I did somewhere along the way.

When I was done, unfortunately, the e-mail accounts that showed up when I ran Thunderbird Portable were still not showing the contents that I wanted them to show.  For example, my Hotmail account was there, but its Inbox was empty, whereas the Hotmail Inbox on Thunderbird for Linux had contained a dozen e-mail messages.  I could see, moreover, that the Data\profile\Mail\pop3.live.com folder contained an Inbox that was 96MB in size.  That was larger than I would have expected, and in any case much larger than an Inbox containing nothing, which is what Thunderbird Portable was showing me.

It seemed that Thunderbird Portable was recognizing the e-mail accounts themselves, but was drawing the contents of those accounts from the wrong place.  I verified this by removing the entire Mail subfolder from Thunderbird Portable.  When I started it up, it was still seeing the same few old items in the same accounts.  I thought it might have observed or figured out where I had moved the Mail folder, so I removed it from that computer entirely; yet Portable was still seeing those same ghostly remnants of some previous state of my Thunderbird for Linux installation.

It took a bit of effort to figure out where those ghostly remains were hanging out.  Portable wasn't drawing them from Data\profile\Cache; they persisted even after I emptied that.  To find the answer, I started Portable, changed the system date to a year in the future, copied one of those old e-mail messages from one folder to another, changed the system date back to the correct year, and exited Portable.  Then I copied the entire Portable folder to a workspace folder elsewhere on the computer, and searched for files bearing that future year's date.  Aside from cache files and scripts, there turned out to be only a handful of files dated in that future year.

That effort led to the discovery that the Data\profile\prefs.js file that I had brought over from Ubuntu was not suited for Windows.  I went to the original backup of my Thunderbird for Windows Portable and copied its prefs.js file to the Portable installation that I was tinkering with, thus overwriting the Ubuntu prefs.js file.  Both of them began with a warning:  "Do not edit this file."  Instead, the warning said, I could follow the instructions provided on a webpage that, as it turned out, was no longer in existence.  A different webpage did advise me to edit prefs.js directly.  Again, of course, I would want to do this while Thunderbird was not running; and if there was any doubt about that, Windows Task Manager (Ctrl-Alt-Del > Processes tab) would confirm whether there was an instance of thunderbird.exe or ThunderbirdPortable.exe currently running.

I opened prefs.js in Notepad, widened the Notepad window to prevent lines from wrapping, and took a look.  I decided I didn't know exactly how to edit prefs.js, so I tried the alternative that the instructions at the top of prefs.js seemed to prefer:  I started Firefox, typed about:config in the address line, and looked to see what was there.  (Note that I did not have any other copies or versions of Thunderbird installed on that computer, else things could have become very confusing.)  I searched for instructions, and eventually realized that it might not make sense to use about:config to change system preferences for a portable program.

So I tried another search.  This led to a webpage that led, eventually, to a mozillaZine webpage that advised me to start over and try using the Kaosmos ImportExportTools utility.  So I made a fresh start, replacing my munged-up Thunderbird Portable with a copy of the backup, and then I installed the ImportExportTools utility as instructed.  Then, in Thunderbird Portable, I went to Tools > ImportExportTools > Import mbox file.  At this point, I had to ask myself:  What, exactly, is an mbox file?  A search led to the discovery that mbox is an e-mail storage format that didn't seem very relevant to Thunderbird's own storage format

To test this, I went ahead with where I was in the ImportExportTools process:  I selected the "Select a directory where searching the mbox files to import (also in subdirectories)" option, and pointed it toward the top level of the folder I had copied over from Ubuntu Thunderbird.  To my surprise, the tool asked me if I wanted to import various programs.  I said no to parentlock and yes to all the other folders it asked me about.  After asking me about those folders, it didn't seem to be doing anything, except that I could see movement in the green progress bar at the bottom of the screen.  When it seemed to be finished, I didn't see any change in Thunderbird's list of folders.  I killed and restarted Thunderbird.  Still no change.  I poked around and then, whoa, I discovered that it had imported everything, including my archives, into the Hotmail Inbox folder (not the actual online one -- just the copy of it that Thunderbird keeps).  I killed T-bird again, made a backup copy of this remarkable state of Thunderbird Portable, restarted the program, and began moving and rearranging folders.

This was looking good, but there were still some things to fix.  First, in T-bird Portable, I tried sending a message that I had kept in the Hotmail drafts folder in Thunderbird for Ubuntu.  I got this message:

Send Message Error
Sending of message failed.
An error occurred sending mail.  Unable to establish a secure link with SMTP server smtp.live.com using STARTTLS since it doesn't advertise that feature.  Switch off STARTTLS for that server or contact your service provider.
A search and then a refined search led to the quick answer that I just had to stop my avast! antivirus software from scanning outgoing messages.

Next, I wanted to get rid of some Local Folders, especially the Inbox and Outbox.  I found a thread that made me think these folders were a product of Smart Folders, which would supposedly combine all of my e-mail inboxes into one Inbox, etc.  I did not want this.  Actually, I wasn't sure this was even the correct explanation, because I was seeing new incoming messages in my Hotmail Inbox, and they were not being mirrored in my Local Folders Inbox.  The advice I got from Yahoo! Answers, usually a font of goofy bewilderment, was as follows:
You can't remove the Smart Folders account using Tools -> Account Settings. You need to either edit prefs.js with a text editor or use the Config editor to delete the account from mail.accountmanager.accounts.
I was inclined to believe this because I had just run across another webpage with more or less the same conclusion.  But the advice on that webpage was oriented toward deleting all local folders, whereas I was using the Local Folders heading as the place to park my e-mail archive.  I right-clicked and saw, from Properties, that Outbox folder was located at Data\profile\Mail\Local Folders\Unsent Messages.  I quit T-bird, made a backup copy of the whole T-bird Portable folder, went into that Local Folders folder in Windows Explorer, and deleted the Unsent Messages entries.  I then restarted T-bird.  No joy.  As expected, the Outbox was still there and the Unsent Messages entries were back.  A new search led to a blanket statement that you could not delete the Outbox because it served an essential function, different from a Drafts folder:  it held messages that the user had tried to send but (because of e.g., no Internet connection) had not yet actually been sent.

So I turned to the next problem arising from the import into Thunderbird Portable for Windows.  I now had two top-level folders appearing at the left side of the T-bird window.  One was for my Hotmail account; the other was for Local Folders.  There should have been a third one, for another e-mail account that had appeared as a top-level folder in T-bird in Ubuntu.  This seemed to be a simple matter of going into T-bird Portable > File > New > Mail Account and entering the information about the account as it was recorded in T-bird for Ubuntu.  But the Mail Account Setup process stayed stuck for a long time on "Looking up configuration:  Trying common server names."  I finally went into Manual Setup and got it working that way.  And with that, the project was done.  I had transitioned from Thunderbird (Ubuntu) to Thunderbird Portable for Windows.

Sunday, May 16, 2010

Importing Microsoft Word Autocorrect Entries into OpenOffice.org Writer

I had been looking, for some years, for a way to import my list of AutoCorrect entries from Microsoft Word 2003 into the OpenOffice.org (OOo) word processing program.

In Word, I had found AutoCorrect invaluable for converting shorthand expressions into longer terms, saving me a lot of typing. For example, I could type “fttt” and watch it expand to “from time to time,” having previously defined it as such. My list of Word AutoCorrect terms had grown long, into the thousands of entries, so I could not just retype them into OOo Writer manually.

I did know how to export the AutoCorrect entries from Word to a text file. There were apparently several macros available for this purpose. The challenge had been in getting the items from there to Writer. A Linuxtopia webpage now suggested a possible approach, however, and I decided to explore it.

My first step was to get into Writer’s DocumentList.xml file. To do this, in Ubuntu’s Nautilus (i.e., File Browser) I went to /usr/lib/openoffice/basis-link/share/autocorr. I double-clicked on acor_en-US.dat (there were files for other languages and for other flavors of English). There was DocumentList.xml. Now, what to do with it? I right-clicked on it and chose Extract > Extract. This gave me an error message: “Extraction not performed. You don’t have the right permissions.” So I went into Applications > Accessories > Terminal and typed “sudo nautilus,” and then, using that superuser File Browser session, went back to that same autocorr folder and tried again. This time, I didn’t try extracting; I just right-clicked on acor_en-US.dat and chose “Open with Archive Manager” and then right-clicked on DocumentList.xml and chose “Open with” and chose gedit. I went to the end of the file, right before the “</block-list:block-list>” entry, and copied the whole previous entry. In my case, it was the one that would change “yuor” to “your.” In full, it read like this:

<block-list:block block-list:abbreviated-name="yuor" block-list:name="your"/>
They all seemed to follow that same format.  So apparently it was just a matter of getting my Word abbreviations into that form.  To test this, I added an entry right after that “your” entry.  Mine read like this:
<block-list:block block-list:abbreviated-name="yr" block-list:name="your"/>
After making that change, I saved the file.  This provoked a File Roller message:  “Update the file ‘DocumentList.xml’ in the archive ‘acor_en-US.dat’?”  I said yes, i.e., Update.  Then I started Writer and tried typing “yr.”  It didn’t work.  It would correct “yuor” to “your,” but it wouldn’t correct “yr” to “your.”  I rebooted the system, in case that would make a difference, and tried again.  It didn’t.  Yr was still not listed in Writer’s autocorrect replacement list.  I went back and looked at the end of DocumentList.xml.  “Yr” was still there.  Had I not entered it correctly?  It looked like I might have entered it twice, possibly from a previous try at the same thing.  I made sure there was just one entry for “yr.”  Then it occurred to me to delete the one for “yuor” and see what would happen.  Or, even better, I deleted the one for “yr,” the one that I had added, and I changed the one for “yuor” to be for “yr” instead.  I went back into DocumentList.xml but, what’s this, there were two entries for “yr” again.  Then I realized that the file edit time had not changed:  it seemed I was editing and saving the changes, no error messages, but I hadn’t come in as root, so there was not anything actually happening.  Editing as root, I saw another problem:  I had apparently inserted a copy of the list-ending “/block-list:block-list” command before my “yr” entry.  So perhaps Writer wasn’t going beyond that, and this was why it wasn’t seeing the “yr” item.  I made those changes, started Writer, and it worked!  “Yr” became “your.”  I went into Writer’s AutoCorrect options, looked at the end of the list, and sure enough, there was “yr.”

So now the mission was to incorporate a bazillion Word AutoCorrect entries into this DocumentList.xml file.  Or, no, as I thought of it, I decided the first step was to make a backup copy of this xml file and then delete its contents.  I had been working with my Word AutoCorrect list for years.  I didn’t need any surprises from whatever might be in DocumentList.xml.  Actually, to make it easier, I just made a quick copy of the whole acor_en-US.dat file.  Then, in DocumentList.xml, I deleted everything except the file starting and file ending lines:

<?xml version="1.0" encoding="UTF-8"?>
<block-list:block-list xmlns:block-list="http://openoffice.org/2001/block-list">

</block-list:block-list>

Since I would probably be doing this again – adding to the OOo AutoCorrect list from the Word AutoCorrect list, or possibly vice versa – I decided to manage it all through an Excel 2003 spreadsheet.  This, I thought, would also be a good way to compare the AutoCorr lists that I had developed on different computers.  That is, I was using AutoCorrect on more than one computer, and it seemed likely that there would be some cases where those lists were not compatible.  So I began with that part of the project.  I ran the AutoCorrect macro in Word on each computer and brought all of the resulting wordlists together into one folder.  I opened one of those wordlists, copied the whole thing, waited a few minutes to make sure it was all there, and pasted it all into an Excel spreadsheet.  Here, too, I wished the AutoCorrect feature included a column indicating the date last used, because a lot of these entries were totally unfamiliar to me and others were for things I was no longer writing about.  Probably I should have done this spreadsheet thing when I first installed Word.  Then it occurred to me that I could set up a virtual machine, install Word on it, and do something like that now.  But without manual examination, I still wouldn’t be able to tell which of those original Word AutoCorr entries I had ever used.

I did manage to come up with some sorting rules that helped somewhat.  After deleting exact duplicates from the several combined AutoCorr files, I sorted alphabetically according to Value (i.e., the term that resulted from the auto-correction) and then according to value length.  For example, I had given “acl” a value of “actual,” and Word came with “actualyl” as also having a value of “actual.”  I could have left both, but it seemed pretty unlikely that I would let a paper go out with “actualyl” in it (not to mention “additinal” and “adequit”).  Actually, I reasoned, I would rather risk letting a paper go out with “actualyl” in it than to endure the insult of having such a spelling correction in my AutoCorrect file.  So I deleted a bunch of those.  I also searched for items containing a space, since those tended to be from Word, not me (e.g., “witht he” becomes “with the”).  I searched for items of the same length before and after, since these tended to be Word’s typo corrections.  When I was done, I copied and pasted it from the Excel file back into the Word AutoCorr list.  Doing that involved creating a new table with enough rows to accommodate all of the Excel entries, highlighting all those empty cells, and pasting the Excel cells into the highlighted space.  There were some extra rows, which Word redundantly filled by starting over at the start of the table and continuing until all rows were filled; I had to delete those.

The next step was to get rid of the existing AutoCorrect entries in Word, so that the unwanted ones that I had deleted would really be gone.  I did this by creating a Word macro to remove them all.  I had no idea how to do this, but it was easy:  in Word 2003, I went into Tools > Macro > Macros > Create.  It had a space for my new macro, starting with Sub AddTBMenuItem() and continuing on to End Sub.  I pretty much replaced that with the following macro, posted in 2001:

Sub RemoveAllDefaultAutoCorrects()
Dim aCor As AutoCorrectEntry
If MsgBox("This is a very destructive macro. Be sure that you " & vbCr & _
"want to delete all the AutoCorrect entries. There is no " & vbCr & _
"for this action. Click OK to continue", vbCritical + vbOKCancel, "CAUTION") _
= vbOK Then
For Each aCor In Application.AutoCorrect.Entries
aCor.Delete
Next aCor
End If
End Sub

I closed that, went back into Tools > Macro > Macros, selected that new macro entry, and ran it.  I gathered from somewhere that Word would restore the old list if you didn’t replace it with at least one new AutoCorrect entry, so I created a dummy one, exited Word, and then came back in to see what it looked like.  Sure enough, there was only that one dummy entry.  So now I ran the macro to restore my new list, and that took care of getting Word’s AutoCorr list updated.

Now, how to do the same thing in OOo Writer?  Using the format shown in that Linuxtopia webpage, I went back to the Excel spreadsheet, added another column on the right side, and used text concatenation to add all the missing stuff – basically, everything other than “yuor” and “your” in that example.  The formula I used was this:
=”<block-list:block block-list:abbreviated-name=”&CHAR(34)&A4&CHAR(34)&”block-list:name=&CHAR(34)&B4&CHAR(34)&”/>”
CHAR(34) was the Excel command for a regular (double) quotation mark.  I had to use CHAR(34) because the quotation mark means something different.  This formula said, take the name in cell A4 (e.g., “yuor”) and replace it with the value in cell B4 (e.g., “your”).  So I copied that formula all the way down the spreadsheet, in my column E (using column D to show the date when I did this, for future reference).  Then I copied all of those cells from column E into Notepad, made sure that Format > Word Wrap was turned off, and saved that as AC.TXT.  Back in Ubuntu, I opened AC.TXT in gedit.  Testing confirmed that OOo Writer was going to have a hard time with items that gedit displayed in funky format, like these:




Most of the items that caused problems that way were due to the use of smart apostrophes (i.e., single quotes) in Word.  So back in Windows, in Notepad, I opened AC.TXT, found an example of a smart apostrophe, highlighted and copied it into the Find & Replace box, and replaced it with a simple apostrophe.  I made a note in the spreadsheet, next to these items, to indicate that they were not compatible with Writer.  Word's em dash () was also problematic as an import into Writer, so I had to replace it, in this imported list, with two hyphens (--).

With these changes made, back in Ubuntu, I was ready to paste the revised AC.TXT into DocumentList.xml.  I closed Writer, did the paste, started Writer, and tried it out.  It didn’t work.  I looked at the AutoCorr list.  It had imported only a few items.  It looked like it had stopped at an item containing an ampersand (&).  I deleted that item from DocumentList.xml and tried again.  Now its AutoCorr list was longer, but still only a fraction.  Sure enough, it had stopped at another ampersand.  I went back to the spreadsheet and deleted or changed all items containing an ampersand, and marked them on the spreadsheet for incompatibility as well.  Trying again:  still no cigar.  This time, it seems there was an item in my list that was already in quotation marks.  So I was trying to import something like ““This”” and Writer wasn’t buying it.  I fixed that and tried again.  This time for sure.  It worked.  I had the entire list, and I played with it.  It looked like they were all going to work.  I doctored up the list by putting a copy of Writer’s special character for the em dash into a document (Insert > Special Character > Box Drawing) and then copying it into the places in the Tools > AutoCorrect list where I had had to import double hyphens (--) instead.  At some point, I would probably do the same with the smart apostrophes, ampersands, and other items if I decided to use Writer frequently.

So it worked.  I could now use my list of abbreviations in OOo Writer instead of having to use Word.

Wednesday, December 30, 2009

Sorting and Manipulating a Long Text List to Eliminate Some Files

In Windows XP, I made a listing of all of the files on a hard drive.  For that, I could have typed DIR *.* > OUTPUTFILE.TXT, but instead I used PrintFolders.  I selected the option for full pathnames, so each line in the file list was like this:  D:\FOLDER\SUBFOLDER\FILENAME.EXT, along with date and file size information.

I wanted to sort the lines in this file list alphabetically.  They already were sorted that way, but DIR and PrintFolders tended to insert blank lines and other lines (e.g., "=======" divider lines) that I didn't want in my final list.  The question was, how could I do that sort?  I tried the SORT command built into WinXP, but it seemed my list was too long.  I tried importing OUTPUTFILE.TXT into Excel, but it had more than 65,536 lines, so Excel couldn't handle it.  It gave me a "File not loaded completely" message.  I tried importing it into Microsoft Access, but it ended with this:

Import Text Wizard

Finished importing file 'D:\FOLDER\SUBFOLDER\OUTPUTFILE.TXT to table 'OUTPUTTXT'.  Not all of your data was successfully imported.  Error descriptions with associated row numbers of bad records can be found in the Microsoft Office Access table 'OUTPUTFILE.TXT'.

And then it turned out that it hadn't actually imported anything.  At this point, I didn't check the error log.  I looked for freeware file sorting utilities, but everything was shareware.  I was only planning to do this once, and didn't want to spend $30 for the privilege.  I did download and try one shareware program called Sort Text Lists Alphabetically Software (price $29.99), but it hung, probably because my text file had too many lines.  After 45 minutes or so, I killed it.

Eventually, I found I was able to do the sort very quickly using the SORT command in Ubuntu.  (I was running WinXP inside a VMware virtual machine on Ubuntu 9.04, so switching back and forth between the operating systems was just a matter of a click.)  The sort command I used was like this:
sort -b -d -f -i -o SORTEDFILE.TXT INPUTFILE.TXT
That worked.  I edited SORTEDFILE.TXT using Ubuntu's GEDIT program (like WinXP's Notepad).  For some reason, PrintFolders (or something) had inserted a lot of lines that did not match the expected pattern of D:\FOLDER\SUBFOLDER\FILENAME.EXT.  These may have been shortcuts or something.  Anyway, I removed them, so everything in SORTEDFILE.TXT matched the pattern.

Now I wanted to parse the lines.  My purpose in doing the file list and analysis was to see if I had any files that had the same names but different extensions.  I suspected, in particular, that I had converted some .doc and .jpg files to .pdf and had forgotten to zip or delete the original .doc and .jpg files.  So I wanted to get just the file names, without extensions, and line them up.  But how?  Access and Excel still couldn't handle the list.

This time around, I took a look at the Access error log mentioned in its error message (above).  The error, in every case, was "Field Truncation."  According to a Microsoft troubleshooting page, truncation was occurring because some of the lines in my text file contained more than 255 characters, which was the maximum Access could handle.  I tried importing into Access again, but this time I chose the Fixed Width option rather than Delimited.  It only went as far as 111 characters, so I just removed all delimiting lines in the Import Text Wizard and clicked Finish.  That didn't give me any errors, but it still truncated the lines.  Instead of File > Get External Data > Import, I tried Access's File > Open command.  Same result.

I probably could have worked through that problem in Access, but I had not planned to invest so much time in this project, and anyway I still wasn't sure how I was going to use Access to remove file extensions and folder paths so that I would just have filenames to compare.  I generally used Excel rather than Access for that kind of manipulation.  So I considered dividing up my text list into several smaller text files, each of which would be small enough for Excel to handle.  I'd probably have done that manually, by cutting and pasting, since I assumed that a file splitter program would give me files that Excel wouldn't recognize.  Also, to compare the file names in one subfile against the file names in another subfile would probably require some kind of lookup function.

That sounded like a mess, so instead I tried going at the problem from the other end.  I did another directory listing, this time looking only for PDFs.  I set the file filter to *.pdf in PrintFolders.  I still couldn't fit the result into Excel, so I did the Ubuntu SORT again, this time using a slightly more economical format:
sort -bdfio OUTPUTFILE.TXT INPUTFILE.TXT
This time, I belatedly noticed that PrintFolders and/or I had somehow introduced lots of duplicate lines, which would do much to explain why I had so many more files than I would have expected.  As advised, I used another Ubuntu command:
sort OUTPUTFILE.TXT | uniq -u
to remove duplicate lines.  But this did not seem to make any difference.  Regardless, after I had cleaned out the junk lines from OUTPUTFILE.TXT, it did all fit into Excel, with room to spare.  My import was giving me lots of #NAME? errors, because Excel was splitting rows in such a way that characters like "-" (which is supposed to be a mathematical operator) were the first characters in some rows, but were followed by letters rather than numbers, which did not compute.  (This would happen if e.g., the split came at the wrong place in a file named "TUESDAY--10AM.PDF."  So when running the Text Import Wizard, I had to designate each column as a Text column, not General.

I then used Excel text functions (e.g., MID and FIND) on each line, to isolate the filenames without pathnames or extensions.  I used Excel's text concatenations functions to work up a separate DIR command for each file I wanted to find.  In other words, I began with something like this:
D:\FOLDER\SUBFOLDER\FILENAME.EXT

and I ended with something like this:
DIR "FILE NAME."* /b/s/w >> OUTPUT.TXT

The quotes were necessary because some file names have spaces in them, which confuses the DIR command.  I forget what the /b and other options were about, but basically they made the output look the way I wanted.  The >> told the command to put the results in a file called OUTPUT.TXT.  If I had used just one > sign then that would have meant I wanted OUTPUT.TXT to be recreated every time a match was found.  Using two >> signs was an indication that OUTPUT.TXT should be created if it does not yet exist, but otherwise the results of the command should just be appended to whatever is already in OUTPUT.TXT.

In cooking up the final batch commands, I would have been helped by the MCONCAT function in the Morefunc add-in, but I didn't know about it yet.  I did use Morefunc's TEXTREVERSE function in this process, but I found that it would crash Excel when the string it was reversing was longer than 128 characters.  Following other advice, I used Excel's SUBSTITUTE command instead.

I took the thousands of resulting commands (such as the DIR FILENAME.* >> OUTPUT.TXT shown above), one for each file type (e.g., FILE NAME.*) that I was looking for, into a DOS batch file (i.e., a text file created in Notepad, with a .bat extension, saved in ANSI format) and ran it.  It began finding files (e.g., FILENAME.DOC, FILENAME.JPG) and listing them in OUTPUT.TXT.  Unfortunately, this thing was running very slowly.  Part of the slowness, I thought, was due to the generally slower performance of programs running inside a virtual machine.  So I thought I'd try my hand at creating an equivalent shell script in Ubuntu.  After several false starts, I settled on the FIND command.  I got some help from the Find page in O'Reilly's Linux Command Directory, but also found some useful tips in Pollock's Find tutorial.  It looked like I could recreate the DOS batch commands, like the example shown above, in this format:

find -name "FILE NAME.*" 2>/dev/null | tee -a found.txt

The "-name" part instructed FIND to find the name of the file.  There were three options for the > command, called a redirect:  1> would have sent the desired output to the null device (i.e., to nowhere, so that it would not be visible or saved anywhere), which was not what I wanted; 2> sent error messages (which I would get because the lost+found folder was producing them every time the FIND command tried to search that folder) to the null device instead; and &> would have sent both the standard output and the error messages to the same place, whatever I designated.  Then the pipe ("|") said to send everything else (i.e., the standard output) to TEE.  TEE would T the standard output; that is, it would send it to two places, namely, to the screen (so that I could see what was happening) and also to a file called found.txt.  The -a option served the same function as the DOS >> redirection, which is also available in Ubuntu's BASH script language, which is what I was using here:  that is, -a appended the desired output to the already existing found.txt, or created it if it was not yet existing.  I generated all of these commands in Excel - one for each FILE NAME.* - and saved them to a Notepad file, as before.  Then, in Ubuntu, I made the script executable by typing "chmod +x " at the BASH prompt and then ran it by typing "./" and it ran.  And the trouble proved to be worthwhile:  instead of needing a month to complete the job (which was what I had calculated for the snail's-pace search underway in the WinXP virtual machine), it looked like it could be done in a few hours.

And so it was.  I actually ran it on two different partitions, to be sure I had caught all duplicates.  Being cautious, I had the two partitions' results output to two separate .txt files, and then I merged them with the concatenation command:  "cat *.txt > full.lst."  (I used a different extension because I wasn't sure whether cat would try to combine the output file back into itself.  I think I've had problems with that in DOS.)  Then I renamed full.lst to be Found.txt, and made a backup copy of it.

I wanted to save the commands and text files I had accumulated so far, until I knew I wouldn't need them anymore, so I zipped them using the right-click context menu in Nautilus.  It didn't give me an option to simultaneously combine and delete the originals.


Next, I needed to remove duplicate lines from Found.txt.  I now understood that the command I had used earlier (above) had failed to specify where the output should go.  So I tried again:

sort Found.txt | uniq -u >> Sorted.txt

This produced a dramatically shorter file - 1/6 the size of Found.txt.  Had there really been that many duplicates?  I wanted to try sorting again, this time by filename.  But, of course, the entries in Sorted.txt included both folder and file names, like this:

./FOLDER1/File1.pdf
./SomeotherFolder/AAAA.doc
Sorting normally would put them in the order shown, but sorting by their ending letters would put the .doc files before the .pdfs, and would also alphabetize the .doc files by filename before foldername.  Sorting them in this way would show me how many copies of a given file there had been, so that I could eyeball the possibility that the ultimate list of unique files would really be so much shorter than reported in Found.txt.  I didn't know how to do that in bash, so I posted a question on it.


Meanwhile, I found that the output of the whole Found.txt file would fit into Excel.  When I sorted it, I found that each line was duplicated - but only once.  So plainly I had done something wrong in arriving at Sorted.txt.  From this point, I basically did the rest of the project in Excel, though it belatedly appeared that there were some workable answers in response to my post.

Sunday, June 22, 2008

Importing AutoCorrect Entries from Microsoft Word into OpenOffice Writer

Microsoft Word allows users to save shortcuts that will correct or expand what they type. For example, if I type "hte," Word has (I think) a built-in correction to "the." Word knows that "hte" is not a word. I have added a lot of other shortcuts to cut down on the typing: "BO," for example, becomes "Barack Obama" if I type "BO" and then hit the spacebar or use some other punctuation. The challenge, for me, was to import those thousands of built-in and added shortcuts from Word to OpenOffice.org's Writer program. I had posted a question on the matter some time back, but so far it has not yet drawn an answer I have found workable for my purposes. Therefore, I decided to try modifying some advice I had found posted elsewhere. The following is a complete description of the steps I took: 1. I used Method 1 (using AutoCorrect.dot) from http://word.mvps.org/FAQs/Customization/ExportAutocorrect.htm. In Word 2003, I clicked on the button to make a Backup of my Word AutoCorrect entries. That gave me a Word document entitled "AutoCorrect Backup Document." 2. I copied the entire document and pasted it into Microsoft Excel. In Excel, I deleted all rows that did not have actual autocorrection values (e.g., I deleted the column headings). I also deleted all columns other than the actual before-and-after values. (In my case, there was just one such column, called RTF, filled with entries of "FALSE.") I saved this Excel spreadsheet as AC.XLS. 3. Find the OOo language file you're using. For me, using US English, that file was called acor_en-US.dat, and was located (by default) in C:\Program Files\OpenOffice.org 2.4\share\autocorr. I will call this simply the DAT file. 4. Although it claims to be a DAT file, it is actually a zipped file, containing several different files. Use your file zip utility to view the contents of the DAT file. Inside it, you will see a file called DocumentList.xml. You can view the contents of DocumentList.xml using Notepad. (Some of these steps may not be as straightforward for you as they were for me. I'm using 7-Zip for my zipper and OpenWith (a Windows Explorer extension) to open DocumentList.xml using Notepad without having to extract the file first. But whatever. Other tools may work as well or better.) 5. With Notepad's WordWrap feature turned off, here's what I saw at the start of DocumentList.xml: [?xml version="1.0" encoding="UTF-8"?][block-list:block-list list="http://openoffice.org/2001/block-list"][block-list:block name="-->" name="→"][block-list:block name="->" name="->"][block-list:block name="(C)" name="©"][block-list:block name="(R)" name="®"] and it basically just went down the list from there. What I saw at the end of DocumentList.xml was this: [block-list:block name="yuo" name="you"][block-list:block name="yuor" name="your"][/block-list:block-list] Actually, that wasn't exactly what I saw. My blog website here, Blogger.com, is too smart for me. It automatically converts HTML coding into HTML, so I can't show you exact HTML. I have had to modify it for this presentation. The modification I have made has been to replace angle brackets with square brackets. In other words, when you see "[" above, please replace it in your own typing with "<" and when you see "]" above, please replace it with ">". Also, be advised that there are no line breaks in the DocumentList.xml file. It just runs on without interruption from beginning to end. It is not like the nice, organized table that AutoCorrect.dot gives you. So when you are inserting additional AutoCorrect items into DocumentList.xml, you need to just stick them into the flow, not put each one on its own separate line. As the foregoing materials from the start and end of DocumentList.xml show, all I had to do was to insert my own AutoCorrect entries between the beginning and the end. The beginning (before the first AutoCorrect entry) was like this: [?xml version="1.0" encoding="UTF-8"?][block-list:block-list list="http://openoffice.org/2001/block-list"] and the ending was simply [/block-list:block-list] (Remember, again, that you need to type ">" where you see "]" etc. in this presentation.) In between the beginning and the ending, as shown by the examples above (where e.g., "(C)" becomes "©"), the entries each have this format: [block-list:block name="BEFORE" name="AFTER"] So if I wanted to have only one AutoCorrect entry in OOo, replacing "BO" with "Barack Obama," here would be my complete DocumentList.xml file: [?xml version="1.0" encoding="UTF-8"?][block-list:block-list list="http://openoffice.org/2001/block-list"][block-list:block name="BO" name="Barack Obama"][/block-list:block-list] Therefore, going back to my AC.XLS file in Excel, here's what I had to do: 6. Insert a column before the BEFORE column. In other words, the new column A in my spreadsheet would be blank, and column B would contain the characters to be replaced ("BO" in the present example). The purpose of this blank column, and of other blank columns C and E discussed below, is to contain material that we are going to combine together into one grand entry in column F. The steps described below provide a basic Excel technique that you may find useful for a variety of applications in the future. 7. Insert a column between the BEFORE and AFTER column. In other words, column C in my spreadsheet would now be blank, and column D would contain the replacement ("Barack Obama," in the present example). 8. In the blank column A, on the first row of the spreadsheet, type the stuff that appears on each individual replacement line before the BEFORE item. In other words, the first cell, at the top left corner of the AC.XLS spreadsheet, should contain just this: [block-list:block name=" including the quotation mark. (Again, you should have an opening angle bracket "<" rather than an opening square bracket "[" on that line.) 9. In the blank column C, type the stuff that appears between the BEFORE and the AFTER items, including the quotation marks, as follows: " name=" Finally, in the blank column E, type the stuff that appears after the AFTER item, including the quotation mark, as follows: "] replacing the closing square bracket "]" with a closing angle bracket ">". 10. Column F can now concatenate (i.e., combine) the contents of columns A through E. This calls for use of Excel's CONCATENATE function. To enter a function in Excel, just type = and then the name of the function, followed by open parentheses. Then follow the pop-up tips and close the parentheses. In this case, the command that goes into cell F1 is: =CONCATENATE(A1,B1,C1,D1,E1) If you are having problems so far, it may be helpful to mention two Excel factoids. First, you can use the ampersand (&) to concatenate instead of CONCATENATE. Second, you can use CHAR(34) to insert a quotation mark manually. 11. What you have entered into the blank cells in row 1 of AC.XLS needs to be copied all the way down. So do that. Fast way: go to cell A1; hit Ctrl-C; hold down Shift and hit the End key and then the Home key; use arrow keys so that only column A is highlighted; and then hit Enter. Do the same with columns C, E, and F. 12. If all has gone well, you should now have a column F filled with entries in the format shown above: [block-list:block name="BEFORE" name="AFTER"] for each of your Word AutoCorrect entries. These are now in OOo Writer format. Now you've got to get them into Writer. Column F in AC.XLS is dependent on columns A through E. To remove column F from Excel, set it in stone so that its contents do not depend on columns A through E anymore. To do that, select column F (Shift End-DownArrow) and then (in Excel 2003) select Edit > Copy and then Edit > Paste Special > Values > OK > Enter. Changes in columns A through E should now have no effect upon column F. 13. Delete columns A through E. Save AC.XLS as AC.TXT in Text (MS-DOS) format. Kill Excel. Open AC.TXT in Word. You will see that Excel found it helpful to insert extra quotation marks everywhere. Make sure that AutoFormat and AutoFormat As You Type are set not to replace straight quotes with smart quotes. Then, using Ctrl-H (or whatever), replace "" (i.e., double double quotes) with " (i.e., just one double quotation mark) throughout the entire file. 14. Another set of unwanted quotation marks may appear at the start and end of each line. Remember, the desired format is [block-list:block name="BEFORE" name="AFTER"] not "[block-list:block name="BEFORE" name="AFTER"]" (Remember to see "<" when I use "[" as discussed above.) To get rid of those unwanted extra starting and ending quotation marks, take advantage of the fact that ^p is Microsoft Word's way of saying it's time to start a new line. (That's for a carriage return. For a line feed, it's ^l (that's ell, not one).) Do a Ctrl-H to replace "^p" (including quotation marks) with ^p (having no quotation marks). Thus "^p" becomes ^p and "[block-list:block name="BEFORE" name="AFTER"]" becomes [block-list:block name="BEFORE" name="AFTER"] for each item in the list. You may have to clean up the first and last items in the list manually. After this, there were still some lingering beginning and ending quotation marks, so I had to run each part of the foregoing replacement again: "^p becomes ^p and ^p" becomes ^p 15. You may need to do some additional clean-up, now or later. In my case, I saw that (C) was now going to produce a question mark (?) rather than a copyright (©) symbol. Evidently Word and/or Excel didn't use standard ASCII for that symbol. That would be something I would have to fix later, probably by inserting the symbol into some text and then copying and pasting it into the AutoCorrect dialog box. I also saw that smart single quotes had sneaked in: "don't" was now "don?t." I started to fix that with a manual search and replace, putting apostrophes (') in place of question marks (?); but then I saw that fancy French accents had also gotten mangled into question marks too, and would require individual attention, so I just made it Replace All and to hell with it. 16. Now it's time to mash it all together, in good old DocumentList.xml format. Do another global replace (Ctrl-H), this time replacing ^p with nothing. Your nice clean lines will disappear, and you'll have just one tremendously long paragraph full of autocorrect commands. 17. Having done a huge amount of work, it's a good idea to do a very belated backup. While we're at it, let's save it as a different file name. In my case, I saved it as AC1.TXT. Choose US-ASCII (Other encoding), don't insert line breaks, and don't allow character substitution. When I did this, I got a warning that text marked in red would not save correctly in the chosen encoding, but I couldn't find any text in red, else I would have tried to fix it in Word. 18. Open AC1.TXT in Notepad. If WordWrap is off, it should look a lot like DocumentList.xml did. You should be looking at the introductory material, like this: [?xml version="1.0" encoding="UTF-8"?][block-list:block-list xmlns:block-list="http://openoffice.org/2001/block-list"] where, again, I have replaced angle with square brackets so this website will not treat it as HTML. After the introductory material, we have the familiar long list of OOo Writer autocorrect entries. If you're interested in merging those into the set you're bringing over from Word, you might want to copy them from Notepad into Excel back around step 5, above, and then sort them to insure you aren't installing duplicates or contradictions. 19. I wasn't interested in OOo's AutoCorrect entries, so I just deleted everything in DocumentList.xml between that introductory material and the ending line, which I will show here in quotation marks so you can see it with its angle brackets intact: "" Then I pasted the full contents of AC1.TXT into that gap between the starting and ending material in DocumentList.xml. 7-Zip allowed me to save this updated version of DocumentList.xml in the DAT archive; otherwise, I'd have had to save it as a separate file and then zip it into the DAT file as an update. 20. Having done all this work, I made a backup of acor_en-US.dat. I ran OOo Writer. It didn't seem to recognize my definitions. So I saved this post at this point, rebooted, and tried it again.