Uniporn's Blog

Here I write about stuff I do, think or wish others would do

How Pandoc saved my nervs

April 10, 2019 — Uniporn

You may or may not have heard of Pandoc, a grat tool when dealing with documents of almost any known type you may dislike or just not have the tools installed to handle them otherwise. This tells a user's story with some /very/ basic pandoc stuff (beside the story I will bore you for sure if you ever used Pandoc before, be warned ;)).

In my case a few minutes ago I decided to create a git repo from stuff I wrote (like lyrics and stuff that wants to be some), but stumbled across a .odt. It was one of my first things to write, back when I was in school - so I can forgive myself for not writing in plaintext. But forgiving is not solving the problem and since I had no libreoffice installed (no big deal, sure), but Pandoc. I am already a bit familiar with pandoc from a friend who handles Emails containing protocols of exams at our students' office and gets to see a whole bunch of formats, and another friend who wrote some neet template for protocols of some students' gremium. So I knew what to expect and it took me longer to write this whole story down, than to open the man page (always a good first call, when you don't know a tool yet) and to find out how to tell pandoc which file to take, what format is to be expected and what format that shall be translated to. That's basically all Pandoc does - you may write your own filters or have complex templates - on a very basic level the understanding stays the same. So here is what I needed today: pandoc -f odt -t plain $src.odt > $dst.txt This means broken down: -f odt: I read this as "from odt" as in "Pandoc, convert from odt to another format!". So to state clearly this is how to specify the format in your sourcefile. -t plain This specifies the target format. You could also read it as "to plaintext" as in "Pandoc, convert from odt to plaintext!". $src.odt Well - so far pandoc has been told what rather exact operation to perform, but not where to get input from. That is where this comes in: yeah, I'm writing this more dramaticly than it is - this is your input file. It doesn't need to have a specific ending in its name or anything, I just wrote the .odt there for clarification. > $dst.txt This has nothing to do with pandoc itself, but with the shell pandoc is executed from: it is a redirect to overwrite existing content and put the output into $dst.txt. However you also can tell pandoc where to put the output, as you may prefer in a script. For that specify -o $dst.txt. And as before I only added an ending to clarify its role in the example. If you want to know whether pandoc already supports the formats you need check out pandoc --list-input formats and pandoc --list-output-formats. Notice that for export to pdf you will need some latex installed - something I will not cover today though it is worth a look ;).

When this little write-up helped you or you'd like to ask something about it or there is something you'd like to tell me about it (I know it's shit - don't tell me that unless you have some reason) feel free to drop me message.

Tags: tools, pandoc