Skip to content

Instantly share code, notes, and snippets.

@ahawthorne
Created February 21, 2012 19:55
Show Gist options
  • Save ahawthorne/1878496 to your computer and use it in GitHub Desktop.
Save ahawthorne/1878496 to your computer and use it in GitHub Desktop.
Build RerwiteRules from CSV
#!/bin/bash
# Pass in a csv file from STDIN as follows. No spaces.
#
# pattern,substitution
# pattern,substitution
if ! [ -t 0 ]; then
STDIN=`cat /dev/stdin`
fi
if [ -z "$STDIN" ]; then
FROM=$1
TO=$2
RULE="RewriteRule ${FROM} ${TO} [R=301,L]"
echo $RULE
exit 0
else
for i in $STDIN; do
echo "RewriteRule ^${i%,*}$ ${i#*,} [R=301,L]"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment