Skip to content

Instantly share code, notes, and snippets.

@kowey
Created June 8, 2010 17:17
Show Gist options
  • Select an option

  • Save kowey/430333 to your computer and use it in GitHub Desktop.

Select an option

Save kowey/430333 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -ne 5 ]; then
echo "Usage: $0 dir-in dir-out ext-in ext-out cmd" >&2
echo "Eg: $0 foo-d bar-d .xml .txt foo2text" >&2
exit 1
fi
DIR_IN=$1
DIR_OUT=$2
EXT_IN=$3
EXT_OUT=$4
CMD=$5
pushd $DIR_IN > /dev/null
DIRS=`find . -type d`
FILES=`find . -name '*'$EXT_IN`
popd > /dev/null
mkdir $DIR_OUT
for d in $DIRS; do
mkdir $DIR_OUT/$d
done
for i in $FILES; do
$CMD "$DIR_IN/$i" > $DIR_OUT/`dirname $i`/`basename $i $EXT_IN`$EXT_OUT
done
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment