Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shell script for converting a batch of files using pandoc. This script will take two arguments: source extension, and target extension. pandoc will attempt to guess the formats.
# pandoc-bulk.sh
#
# This script was created to convert a directory full
# of files into a different format. It uses pandoc to do the conversion.
#
# 1. Install pandoc from http://johnmacfarlane.net/pandoc/
# 2. Copy this script into the directory containing the files
# 3. Ensure that the script has execute permissions: chmod +x pandoc-bulk.sh
# 4. Run the script
#
# By default this will keep the original file
# Usage: pandoc-bulk.sh <source_extension> <target_extension>
# eg. pandoc-bulk.sh rtf md
# $1 = extension of source files
# $2 = extension of target files
source_ext=$1
target_ext=$2
source_files=*.$source_ext
echo "-- Converting $source_ext to $target_ext in `pwd`"
for source_filename in $source_files
do
# extension="${f##*.}"
filename="${source_filename%.*}"
target_filename="$filename.$target_ext"
echo " - $source_filename"
echo " + $target_filename"
pandoc -s -o "$target_filename" "$source_filename"
# uncomment this line to delete the source file.
# rm $source_filename
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.