X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=teeu;h=9a7345bf027b94a069a251296b4bc8d97fb91e4f;hb=8aa7fedebed4c7b707c0fde9f412235f235efce6;hp=44718f94ed6b696c9ee1f706050bff720cabb144;hpb=83e89cc8fc3d1fc682cb1ce813a3d56d8d6c5f51;p=tee-unique diff --git a/teeu b/teeu index 44718f9..9a7345b 100755 --- a/teeu +++ b/teeu @@ -3,26 +3,24 @@ # This program is under GPL v. 3 or later, see teeu() { - local help="Usage: appendu [-h|--help] FILE + local help="Usage: appendu [-h|--help] FILE [LINE] -Tee unique. Append each stdin line if it does not exist in the file. +Tee unique. Append each LINE or if none, each stdin line to FILE if it does not exist in FILE. [-h|--help] display this message" - if [[ $1 == --help || $1 == -h ]]; then echo "$help" return fi - if [[ ${#@} == 0 ]]; then - echo "error: need 1 or more arguments" + if (( ${#@} == 0 )) ; then + echo "teeu error: need 1 or more arguments" echo "$help" return 1 fi - local MAPFILE - mapfile -t + (( ${#@} >= 2 )) && MAPFILE="${@:2}" || mapfile -t for line in "${MAPFILE[@]}"; do grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line" done