simplify and rename to teeu
[tee-unique] / teeu-function
diff --git a/teeu-function b/teeu-function
new file mode 100644 (file)
index 0000000..33347f7
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+# Copyright (C) 2014 Ian Kelling
+# This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
+
+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
+}