Skip to content

Instantly share code, notes, and snippets.

@tarranjones
Last active November 22, 2016 10:38
Show Gist options
  • Save tarranjones/f4b93be9dfbc3ec04feef633442e5cb6 to your computer and use it in GitHub Desktop.
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
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