X-Git-Url: https://iankelling.org/git/?p=tee-unique;a=blobdiff_plain;f=teeu;fp=teeu;h=87ba60bbac9e8e57b63d9e9920215fa3fb28ca33;hp=0000000000000000000000000000000000000000;hb=9742f5f097a6d818d44562e3bc46fb2893f013ce;hpb=ff367964d27678cbbc93aff541e3b45274919668 diff --git a/teeu b/teeu new file mode 100755 index 0000000..87ba60b --- /dev/null +++ b/teeu @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright (C) 2014 Ian Kelling +# This program is under GPL v. 3 or later, see + +appendu() { + local help="Usage: appendu [-h|--help] FILE + +Tee unique. Append each stdin line if it does not exist in the 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" + echo "$help" + return 1 + fi + + local MAPFILE + mapfile -t + for line in "${MAPFILE[@]}"; do + grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line" + done + return 0 +} +teeu "$@"