Over the years, I’ve downloaded a lot of old emails to my laptop, which I saved as .eml files and then converted to .docx, .odt, and .txt files (mostly the last two).

The unfortunate habit of almost everyone (including myself, but no longer!) of quoting the original message as part of an email exchange has left me with text file(s) full of repeated sentences and paragraphs. What I’ve tended to do is to dump all the text from a one on one correspondence into a single file (“Dad-Erinaceus Complete Correspondence.odt,” for example) and then try cleaning it up and re-ordering the messages by date.

Apart from the emails, I have I guess what you’d call a “journal” which is a very long .odt file that runs to about 300 pages or so. Much of this has the same sentences and paragraphs over and over again, but sometimes with slight variations that I would like to keep. So far, in either .odt or .txt files, I’ve started by searching for the first sentence, deleting subsequent appearances of it, and then going on to the next sentence, and so forth. Very time consuming! Is there a faster (and safe) way to do this?

There is quite possibly a very simple solution to this that I haven’t thought of, but I’d be much obliged for any suggestions.

  • pheonixdown@sh.itjust.works
    link
    fedilink
    arrow-up
    4
    ·
    3 months ago

    Python should be able to handle this for you with 100% accuracy at removing duplicated sentences (and headers), with added complexity you could have it even make result files based on unique emails you corresponded with, and it can handle all the various file types and even nested folders if that’s involved.

    Probably could do this in 50-100 lines of code depending on complexity. Runtime should be minutes at most.

    Learning python to do this would probably take a couple to a few hours if you have any familiarity with coding, bit more if you don’t.

      • Zarobi@aussie.zone
        link
        fedilink
        English
        arrow-up
        0
        ·
        3 months ago

        I have good news for you, you get to spend days learning an entire skillset to solve 1 specific problem!

        In all seriousness though, there’s actually a big problem with email “quoting” as you say, that each email client will re create the entire email chain in it’s own format, leading to a complete mess.

        If you still have access to that email client, it might be easier to see if there’s an export feature to export them as actual email files, which would be much easier to process than a word document.

        Another option, if you are ok with “close enough” and some inaccuracies, you could ask an A.I. like Claude to process these files for you.

        Otherwise you’re probably stuck with manual tedious processing. Personally I would just start again and ignore the file you have. Create an actual indexed word document with a table of contents so you can actually find anything. Add a header per email topic, with a sub header per message / reply. Manually copy paste, being careful not to include the quote this time.

        • Alas Poor Erinaceus@lemmy.mlOP
          link
          fedilink
          English
          arrow-up
          0
          ·
          3 months ago

          Text, as far as I know (?) doesn’t take up that much space memory-wise, but on the other hand can you imagine the amount of server space that gets taken up by redundant text from people’s emails (just for starters)?

          Some of my approaches to the apparently much-hated “Inbox Zero” are to be diligent about emptying the trash, not keeping copies of emails in my sent folder, and most importantly, to download messages, personal or professional ones (mostly the former) that I find personally valuable, and then delete the original email so it isn’t floating around forever in cyberspace. This leaves me with lots of txt files, which, as I said above, I then merge all together into one file and then edit. You’d think that there’d be a tool that cleans up the contents of email messages; there do appear to be some online ones, but I don’t trust them. While researching this problem, I found out about “(g)awk” and am now fiddling around with it to see if I can successfully clean up my files without completely messing them up, as in

          awk '!seen[$0]++' input.txt > output.txt

          making sure that I experiment on a duplicated file and not on the original. I barely know what I’m doing here, but I’ll see what I can come up with . . .

          • DJ Putler@lemmy.mlBannedB
            link
            fedilink
            arrow-up
            1
            ·
            3 months ago

            Nice. What do you think about Arcane/Delta Chat’s email functionality? I find the backup & the interface helpful. Easy backups unfortunately not passworded.