Skip to content

Instantly share code, notes, and snippets.

@rahulinux
Last active December 21, 2015 21:29
Show Gist options
  • Save rahulinux/6368252 to your computer and use it in GitHub Desktop.
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 .
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