2017-10-10 11:34:07 +08:00
|
|
|
#!/bin/bash
|
2017-10-10 12:01:15 +08:00
|
|
|
temp_file="temp.sort"
|
|
|
|
num_insertions=0
|
|
|
|
num_duplicates=0
|
2017-10-10 11:34:07 +08:00
|
|
|
|
2017-10-10 12:06:28 +08:00
|
|
|
# Append contents of new_file into main_file
|
2017-10-10 11:34:07 +08:00
|
|
|
# ensuring no duplicates.
|
|
|
|
while read p; do
|
|
|
|
if [ $(grep -w $p $2 | wc -l) -eq 0 ]; then
|
|
|
|
echo $p >> $2
|
2017-10-10 12:01:15 +08:00
|
|
|
num_insertions=$((num_insertions+1))
|
|
|
|
else
|
|
|
|
num_duplicates=$((num_duplicates+1))
|
2017-10-10 11:34:07 +08:00
|
|
|
fi
|
|
|
|
done < $1
|
|
|
|
|
2017-10-10 12:01:15 +08:00
|
|
|
echo "NUMBER OF INSERTIONS: $num_insertions"
|
|
|
|
echo "NUMBER OF DUPLICATES: $num_duplicates"
|
|
|
|
|
2017-10-10 12:06:28 +08:00
|
|
|
# Sort main_file
|
2017-10-10 11:34:07 +08:00
|
|
|
sort $2 > $temp_file
|
|
|
|
cat $temp_file > $2
|
|
|
|
rm -f $temp_file
|
|
|
|
|
|
|
|
#end
|