Created
August 28, 2013 16:55
-
-
Save rahulinux/6368371 to your computer and use it in GitHub Desktop.
Comment Match tags in configuration files and append new one
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
# This Function will handal escaped character / also using sed | |
CommentAppend() { | |
# Comment line and append line below commented line | |
local comment="$( echo "$1" | sed 's/\(\/\)/\\\//g' )" # search this line and comment it | |
local append="$( echo "$2" | sed 's/\(\/\)/\\\//g' )" # Append this line below commented line | |
local InputFile="$3" | |
sed -i "s/^${comment}/#${comment}/g" $InputFile | |
# if string does not exists in input file then add | |
if ! grep "${append}" $InputFile >/dev/null 2>&1; then | |
sed -i "s/#${comment}/& \n${append}/" $InputFile | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment