Skip to content

Instantly share code, notes, and snippets.

@robrecord
Forked from hugorodgerbrown/md_to_rst.sh
Last active August 25, 2018 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robrecord/0a05e451c90bc52566ea92c692779eba to your computer and use it in GitHub Desktop.
Save robrecord/0a05e451c90bc52566ea92c692779eba to your computer and use it in GitHub Desktop.
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