From: Ian Kelling Date: Mon, 11 Aug 2014 17:11:37 +0000 (-0700) Subject: allow line arguments X-Git-Url: https://iankelling.org/git/?p=tee-unique;a=commitdiff_plain;h=ad53fa76300d63ff54840321af31ebcb6bb3ef9a allow line arguments --- diff --git a/teeu b/teeu index 44718f9..5be4b76 100755 --- a/teeu +++ b/teeu @@ -3,9 +3,9 @@ # 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" @@ -15,15 +15,16 @@ Tee unique. Append each stdin line if it does not exist in the file. 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 file="$1"; shift local MAPFILE mapfile -t - for line in "${MAPFILE[@]}"; do + for line in "${@:-$MAPFILE[@]}"; do grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line" done return 0 diff --git a/teeu-function b/teeu-function index cc55ff1..5845aff 100644 --- a/teeu-function +++ b/teeu-function @@ -3,9 +3,9 @@ # 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" @@ -15,15 +15,16 @@ Tee unique. Append each stdin line if it does not exist in the file. 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 file="$1"; shift local MAPFILE mapfile -t - for line in "${MAPFILE[@]}"; do + for line in "${@:-$MAPFILE[@]}"; do grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line" done return 0