Created
May 16, 2023 10:15
-
-
Save reinefjord/2cd27219763454c8352ba0ebdf54f5cf to your computer and use it in GitHub Desktop.
appending to file if line does not 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
#!/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