Skip to content

Instantly share code, notes, and snippets.

@leolovenet
Created February 23, 2014 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leolovenet/9170821 to your computer and use it in GitHub Desktop.
Save leolovenet/9170821 to your computer and use it in GitHub Desktop.
use this script to remove comment line in config file. e.g. $commentdel nginx.conf
#!/bin/bash
#set -x
if [ $# -lt 1 ]; then
echo "Usage: $0 < filepath > [ \# | \; | \/\/ | \<other comment sign>, default: \# ]"
exit 1;
fi
CONFIG_FILE=$1
if [ ! -f ${CONFIG_FILE} ]; then
echo "Error: File \"${CONFIG_FILE}\" not found."
exit 1;
fi
if [ ! -z $2 ]; then
COMMENT_SING=$2
else
COMMENT_SING="#"
fi
egrep -v '^[[:space:]]*'${COMMENT_SING} ${CONFIG_FILE} | sed -e "/^$/d"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment