If you learn how to use and combine various commands it can really speed up work. Today I was looking for a way to turn multiple Org Mode files into a single, readable HTML file. The filenames are in the format 2019-03-17-Sunday.org
, and I wanted them in order of date. I was able to quickly do it like this:
$ cat $(ls -1 | sort | grep org$) | pandoc -f org -t html > output.html
Explanation:
-
cat
– concatenates multiple files to stdout -
$()
– evaluates the commands inside the parentheses -
ls -1
– prints a list of files in one column -
|
– pipes the output of one command into the next command -
sort
– sorts the results (by date in this case) -
grep org$
– this filters out any files that don’t haveorg
as the last part of the filename (excludes directories and backup files that end with a tilde, likefilename.org~
) -
pandoc -f org -t html
– pandoc is a tool to convert between formats, in this case from (-f
) Org Mode to (-t
) HTML -
>
this sends the output to a file namedoutput.html