Union-merge of two files

So you want to merge two files together ? But maybe you would like the content of both files into one ?
So you want to do an union merge of two files ?

Then it is now possible with this small script to use along with the patch/diffs commands
The usage is « patchWithoutDelete file1 file2 fileOutput ».

#!/bin/bash
INPUT1=$1
INPUT2=$2
OUTPUT=$3
cp $INPUT1 $OUTPUT
CHANGES="$(diff -u $INPUT1 $INPUT2 | sed 's/^-\(.*\)$/\1/g')"
HEADER1=""
HEADER2=""
CURRENT=""
SAVED=""
NBLINES=$(echo "$CHANGES" | wc -l)
COUNTPLUS=0
NB=0
PATCHFILE=""
for i in $(seq $NBLINES);do
LINE="$(echo "$CHANGES" | head -n $i | tail -n 1)"
if [ -z "$HEADER1" ];then
HEADER1="$LINE"
PATCHFILE="$PATCHFILE$HEADER1\n"
elif [ -z "$HEADER2" ];then
HEADER2="$LINE"
PATCHFILE="$PATCHFILE$HEADER2\n"
elif [ -z "$CURRENT" ];then
CURRENT="$LINE"
else
if [ ! -z "$(echo "$LINE" | grep '^@@')" ];then
NUMBERBEFORE=$(expr $NB - $COUNTPLUS)
PATCHFILE="$PATCHFILE$(echo "$CURRENT" | sed "s/^@@ -\([0-9]\+\),\([0-9]\+\) +\([0-9]\+\),\([0-9]\+\)/@@ -\1,$NUMBERBEFORE +\3,$NB/g")\n$SAVED"
CURRENT="$LINE"
SAVED=""
COUNTPLUS=0
NB=0
else
if [ ! -z "$(echo "$LINE" | grep '^+')" ];then
COUNTPLUS=$(expr $COUNTPLUS + 1)
fi
NB=$(expr $NB + 1)
SAVED="$SAVED$LINE\n"
fi
fi
done
echo -e "$PATCHFILE" | patch $OUTPUT