Last active
November 22, 2016 10:38
-
-
Save tarranjones/f4b93be9dfbc3ec04feef633442e5cb6 to your computer and use it in GitHub Desktop.
Appends lines of text to a specified file but only if the line doesn't already exist
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 append(){ | |
count=$#; | |
filename=${!count} | |
for i in "$@"; do | |
if ! [[ "$filename" = "$i" ]]; then | |
grep -q -F "$i" $filename || echo "$i" >> $filename | |
fi | |
done | |
} | |
# usage | |
# $ append "line one" "line two" "line one" "line "two" filename.txt | |
# filename.txt | |
#line one | |
#line two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment