44718f94ed6b696c9ee1f706050bff720cabb144
[tee-unique] / teeu
1 #!/bin/bash
2 # Copyright (C) 2014 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
4
5 teeu() {
6 local help="Usage: appendu [-h|--help] FILE
7
8 Tee unique. Append each stdin line if it does not exist in the file.
9
10 [-h|--help] display this message"
11
12
13 if [[ $1 == --help || $1 == -h ]]; then
14 echo "$help"
15 return
16 fi
17
18 if [[ ${#@} == 0 ]]; then
19 echo "error: need 1 or more arguments"
20 echo "$help"
21 return 1
22 fi
23
24 local MAPFILE
25 mapfile -t
26 for line in "${MAPFILE[@]}"; do
27 grep -xFq "$line" "$1" &>/dev/null || tee -a "$1" <<<"$line"
28 done
29 return 0
30 }
31 teeu "$@"