Skip to content

Instantly share code, notes, and snippets.

@paven
Last active August 29, 2015 14:22
Show Gist options
  • Save paven/9d7686eb2428355cc55f to your computer and use it in GitHub Desktop.
Save paven/9d7686eb2428355cc55f to your computer and use it in GitHub Desktop.
replaceOrAdd
#$1 regexp
#$2 replacment
found=false;
#/bin/bash
##replace and write
while IFS='' read -r LINE || [ -n "$LINE" ]; do
if echo $LINE | grep -q "$1"; then
echo $LINE | sed "s/$1/$2/g";
found=true;
else
echo $LINE;
fi
done
##ADD
if ! $found; then
echo $2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment