iankelling.org
/
git
/
tee-unique
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
simplify repo to have one script
[tee-unique]
/
teeu
diff --git
a/teeu
b/teeu
index 87ba60bbac9e8e57b63d9e9920215fa3fb28ca33..948169dbffdd190d66a2cb502ec0807800ef4012 100755
(executable)
--- a/
teeu
+++ b/
teeu
@@
-2,27
+2,25
@@
# Copyright (C) 2014 Ian Kelling
# This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
# Copyright (C) 2014 Ian Kelling
# This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
-
append
u() {
- local help="Usage: appendu [-h|--help] FILE
+
tee
u() {
+ 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"
[-h|--help] display this message"
-
if [[ $1 == --help || $1 == -h ]]; then
echo "$help"
return
fi
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
echo "$help"
return 1
fi
-
local MAPFILE
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
for line in "${MAPFILE[@]}"; do
grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
done