Last active
December 21, 2015 21:29
-
-
Save rahulinux/6368252 to your computer and use it in GitHub Desktop.
Append List of lines, it will check in input file and if it not exists then it will append .
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
function AppendIfnotExists() { | |
while read s | |
do | |
inputFile="$2" | |
# if starting content matched then comment them | |
local startStr=$( echo "${s}" | cut -d" " -f1 ) | |
grep -q "^#${s}" $inputFile || sed -i "s/^$startStr/#$startStr/g" $inputFile | |
if ! grep "^${s}" $inputFile >/dev/null 2>&1; then | |
echo "${s}" >> $inputFile | |
fi | |
done <<< "$1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment