I’m trying to convert every .markdown file in ~/notes/ (and below) to html, using the native Markdown.pl --html4tags script. However, Markdown.pl prints the html to stout, meaning that to convert test.markdown to test.html, I need to run: Markdown.pl --html4tags test.markdown > test.html.
I’m stuck in figuring out how to incorporate piping into a recursive find -exec or find ... | xargs function. The best I’ve come up with is:
for i in `find ~/notes/ -type f -name "*.markdown"` ; do
Markdown.pl --html4tags $i > ${i}.html ;
done
It successfully converts every .markdown file into html, but of course it looks like test.markdown.html instead of test.html.
So basically, I need to be doing something like converting ${i}.markdown into ${i}.html, but I can’t figure out how to encode that in the function. Thanks for any help.
edit: I figured out a way to fix the above script, using basename (which I just discovered):
for i in `find ~/notes/ -type f -name "*.markdown"` ; do
Markdown.pl --html4tags $i > `basename $i .markdown`.html ;
done
This basically converts every .markdown file into html while also stripping the .markdown extension and then adding a .html extension.
I’d be curious to know if there are better ways of doing this, e.g., using find -exec.
Boom!