Created
August 16, 2016 16:15
-
-
Save dale-c-anderson/3146327ae8264564ac74d39d0bc65b3a to your computer and use it in GitHub Desktop.
Strips comments from config files. Can be used with filename arguments, or with pipes.
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 | |
function main () { | |
if [ $# -gt 0 ]; then | |
# Someone sent us a filename | |
cat "$@" | grep -v ^\; | grep -v ^$ | grep -v ^\ $ | grep -v '^#' | |
else | |
if [ -t 0 ]; then | |
# Someone called us without args or pipes. | |
usage | |
else | |
# Someone piped some stdin, or the contents of a file to us | |
DATA="$(cat)" | |
echo "$DATA" | grep -v ^\; | grep -v ^$ | grep -v ^\ $ | grep -v '^#' | |
fi | |
fi | |
} | |
function usage () { | |
echo "Usage:" | |
echo "$(basename "$0") /path/to/file1 [/path/to/file2 ...]" | |
echo "cat /path/to/file | $(basename "$0")" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment