-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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