OT - Help w/ Terminal - textutil & pandoc rtf to markdown conversion


(Greg Schneck) #1

I found THIS on stackoverflow forum. Here is the command line itself:

textutil -stdin -convert html -stdout | pandoc --from=html --to=markdown

Can someone explain stdin and stdout please as opposed to actual file names? I’m guessing that if in Terminal and I am “in” folder named “ABC” (cd “ABC”) this will run on all html files in that folder? I can’t seem to get this to work and my understanding is not good enough to troubleshoot.

Any help/comments appreciated. If you know a conversion tool from rtf to markdown would you let me know please. I basically need to retain bold and italic tags from the rtf.


(Doug Bennett) #2

stdin and stdout refer to reading the file from Unix standard in and writing to standard out.

So in the example above I would replace -stdin with your filename you wish to convert. It apears that the sample comand is “piping” ! to another program called pandoc. Don’t thing thats a standard Mac terminal command, so you may need to install it.


(Greg Schneck) #3

Hi… thanks. Yes. I put in “hard” file names for input and output and I ran only the first half of the command and it did indeed work, converting RTF to HTML. The second half is for a pandoc HTML to RTF conversion. I do have Pandoc installed. I’ll test it separately also then see if I can put the two together. But I’ll probably just setup a macro to launch terminal and run the two separately with given filenames.

Could you expand on your statement:

stdin and stdout refer to reading the file from Unix standard in and writing to standard out.

I don’t understand where it would read from and write to… I’ve tried looking it up but it’s like everyone expects the reader to know what that means.


(Doug Bennett) #4

The stdin is usually your keyboard unless you pipe the input from another process.
stdout would go to your screen.

https://stackoverflow.com/questions/3385201/confused-about-stdin-stdout-and-stderr

As for textutil and most terminal commands you can get to a manual by typing
man textutil

when done type q for quit.
or
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/textutil.1.html

Here is a good article with samples on converting with textutil: