Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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