3
1
I have a folder full of HTML files:
001.htm
002.htm
003.htm
…
I want to run Pandoc on them to convert them to similarly named Markdown files:
001.md
002.md
003.md
This command works on one of them:
pandoc -f html -t markdown 001.htm -o 001.md
And I want to use find
and xargs
to automatically run a similar command on every file in the folder.
I got as far as this:
find *.htm | xargs -I {} -n 1 pandoc -f html -t markdown -o {}
…which truncates every file in the directory, so now I'm asking before I really break something.
What is wrong with my command above, and/or what's a completely different / more efficient way to do this?
2+1. xargs doesn't allow you the same flexibility of filename modification. Do not replace
*.htm
with$(find...)
-- filenames with spaces will be properly handled in the first case but not the second. – glenn jackman – 2013-01-25T19:35:33.5101@glennjackman Unless you set the bash
$IFS
to$'\n'
for that code section, in which case spaces aren't a problem -- newlines still are though. – Daniel Beck – 2013-01-25T20:05:21.940Wow, there are two or three new things about the command line for me to learn from that snippet. Thanks! – 75th Trombone – 2013-01-25T23:44:29.057