Last active
November 3, 2016 23:05
-
-
Save taveras/162860deae8f62a6d774292abe6442f4 to your computer and use it in GitHub Desktop.
Convert Apache redirect map to NGINX format
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
#!/bin/bash | |
# copy file 1 to file 2, and overwrite file 2 if necessary | |
yes | cp $1 ${2}-tmp | |
# %g/^#/normal dd # Deletes all comments | |
# %normal Elcw # Collapses whitespace between segments | |
# %normal A; # Adds semicolon to the end of each line | |
# %g/\S\/\;/normal f;hx # Removes trailling slash for second segment | |
# %g/\/ /normal Ex # Removes trailing slash for first segment | |
# %normal Vgu # Lower cases all characters | |
# wq # Save file and quit | |
# open vim and run the above ex commands | |
# awk '!x[$0]++' # remove duplicate lines without sorting | |
vim ${2}-tmp -c "%g/^#/normal dd" \ | |
-c "%normal Elcw " \ | |
-c "%normal A;" \ | |
-c "%g/\S\/\;/normal f;hx" \ | |
-c "%g/\/ /normal Ex" \ | |
-c "wq" | |
cat ${2}-tmp | awk '!x[$0]++' > $2 | |
rm ${2}-tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment