1*b15c0302SAdrien Destugues#!/bin/bash 2*b15c0302SAdrien Destugues 3*b15c0302SAdrien Destuguesif [ $# -eq 2 ] 4*b15c0302SAdrien Destugues then 5*b15c0302SAdrien Destugues OLD=$1 6*b15c0302SAdrien Destugues NEW=$2 7*b15c0302SAdrien Destugues 8*b15c0302SAdrien Destugues # We need a tab character as a field separator 9*b15c0302SAdrien Destugues TAB=`echo -e "\t"` 10*b15c0302SAdrien Destugues 11*b15c0302SAdrien Destugues #Temporary storage 12*b15c0302SAdrien Destugues TEMPFILE=`mktemp /tmp/catmerge.XXXXX` 13*b15c0302SAdrien Destugues 14*b15c0302SAdrien Destugues # Extract the list of keys to remove 15*b15c0302SAdrien Destugues # Compare (diff) the keys only (cut) ; keep only 'removed' lines (grep -), 16*b15c0302SAdrien Destugues # Ignore diff header and headlines from both files (tail), remove diff's 17*b15c0302SAdrien Destugues # prepended stuff (cut) 18*b15c0302SAdrien Destugues # Put the result in our tempfile. 19*b15c0302SAdrien Destugues diff -u <(cut -f 1,2 $OLD) <(cut -f 1,2 $NEW) |grep ^-|\ 20*b15c0302SAdrien Destugues tail -n +3|cut -b2- > $TEMPFILE 21*b15c0302SAdrien Destugues 22*b15c0302SAdrien Destugues # Reuse the headline from the new file (including fingerprint). This gets 23*b15c0302SAdrien Destugues # the language wrong, but it isn't actually used anywhere 24*b15c0302SAdrien Destugues head -1 $NEW 25*b15c0302SAdrien Destugues # Sort-merge old and new, inserting lines from NEW into OLD (sort); 26*b15c0302SAdrien Destugues # Exclude the headline from that (tail -n +2) 27*b15c0302SAdrien Destugues # Then, filter out the removed strings (fgrep) 28*b15c0302SAdrien Destugues sort -u -t"$TAB" -k 1,2 <(tail -n +2 $OLD) <(tail -n +2 $NEW)|\ 29*b15c0302SAdrien Destugues fgrep -v -f $TEMPFILE 30*b15c0302SAdrien Destugues 31*b15c0302SAdrien Destugues rm $TEMPFILE 32*b15c0302SAdrien Destugues 33*b15c0302SAdrien Destugues else 34*b15c0302SAdrien Destugues echo "$0 OLD NEW" 35*b15c0302SAdrien Destugues echo "merges OLD and NEW catalogs, such that all the keys in NEW that are" 36*b15c0302SAdrien Destugues echo "not yet in OLD are added to it, and the one in OLD but not in NEW are" 37*b15c0302SAdrien Destugues echo "removed. The fingerprint is also updated." 38*b15c0302SAdrien Destuguesfi 39