X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=teeu-function;h=e4705b7afd3e07a3803602cdd9aad9deec0295e1;hb=a468c8cdb5a12fce2487ae9816cdb4501ffffa09;hp=33347f74a0bc9b912be46d2d8dcd7992c4c60552;hpb=9742f5f097a6d818d44562e3bc46fb2893f013ce;p=tee-unique diff --git a/teeu-function b/teeu-function index 33347f7..e4705b7 100644 --- a/teeu-function +++ b/teeu-function @@ -2,28 +2,26 @@ # Copyright (C) 2014 Ian Kelling # This program is under GPL v. 3 or later, see -appendu() { - local help="Usage: appendu [-h|--help] FILE +teeu() { + 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 - for line in "${MAPFILE[@]}"; do + (( ${#@} >= 2 )) && MAPFILE="${@:2}" || mapfile -t + for line in "${$MAPFILE[@]}"; do grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line" done return 0