Skip to content

Instantly share code, notes, and snippets.

@reinefjord
Created May 16, 2023 10:15
Show Gist options
  • Save reinefjord/2cd27219763454c8352ba0ebdf54f5cf to your computer and use it in GitHub Desktop.
Save reinefjord/2cd27219763454c8352ba0ebdf54f5cf to your computer and use it in GitHub Desktop.
appending to file if line does not exist
#!/bin/sh
while read -r line
do
grep -q -s "^$line$" "$1" || echo "$line" >> "$1"
done
# usage: echo "line the might exist" | ./appn.sh myfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment