#!/bin/bash
# concat1.sh: Append the first list ($1) to the second ($2) without duplicates and with sorting.
# Dr. Rolf Freitag. License: Hacktivismo Enhanced-Source Software License Agreement (HESSLA),
# see http://www.hacktivismo.com/about/hessla.php
# Version 1.1, 2009-10-05

# be verbose
set -x

if [ "$#" -ne 2 ]; then
  echo "Error: Not two parameters (the input files); exiting!"
  exit -1
fi

# simple appending
cat "$1" >> "$2"

# tmpfile(s)
tmpfile0="tmpfile0$$$RANDOM"

# sort and make each line unique by deleting duplicate lines
sort "$2" > "$tmpfile0"
uniq "$tmpfile0" > "$2"

# make clean
rm "$tmpfile0"

