From b15c03021da96b5d98ec148c99b9a375ece6f026 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 1 Nov 2011 12:40:51 +0000 Subject: [PATCH] Add catmerge.sh, a shellscript for easily merging an existing but outdated catalog with a newer one in another language. I was not sure where to put it, is this the right place ? git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43059 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- 3rdparty/pulkomandy/catmerge.sh | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 3rdparty/pulkomandy/catmerge.sh diff --git a/3rdparty/pulkomandy/catmerge.sh b/3rdparty/pulkomandy/catmerge.sh new file mode 100755 index 0000000000..1a0b729329 --- /dev/null +++ b/3rdparty/pulkomandy/catmerge.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +if [ $# -eq 2 ] + then + OLD=$1 + NEW=$2 + + # We need a tab character as a field separator + TAB=`echo -e "\t"` + + #Temporary storage + TEMPFILE=`mktemp /tmp/catmerge.XXXXX` + + # Extract the list of keys to remove + # Compare (diff) the keys only (cut) ; keep only 'removed' lines (grep -), + # Ignore diff header and headlines from both files (tail), remove diff's + # prepended stuff (cut) + # Put the result in our tempfile. + diff -u <(cut -f 1,2 $OLD) <(cut -f 1,2 $NEW) |grep ^-|\ + tail -n +3|cut -b2- > $TEMPFILE + + # Reuse the headline from the new file (including fingerprint). This gets + # the language wrong, but it isn't actually used anywhere + head -1 $NEW + # Sort-merge old and new, inserting lines from NEW into OLD (sort); + # Exclude the headline from that (tail -n +2) + # Then, filter out the removed strings (fgrep) + sort -u -t"$TAB" -k 1,2 <(tail -n +2 $OLD) <(tail -n +2 $NEW)|\ + fgrep -v -f $TEMPFILE + + rm $TEMPFILE + + else + echo "$0 OLD NEW" + echo "merges OLD and NEW catalogs, such that all the keys in NEW that are" + echo "not yet in OLD are added to it, and the one in OLD but not in NEW are" + echo "removed. The fingerprint is also updated." +fi