Last active
August 29, 2015 14:22
-
-
Save paven/9d7686eb2428355cc55f to your computer and use it in GitHub Desktop.
replaceOrAdd
This file contains hidden or 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
#$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