Skip to content

Instantly share code, notes, and snippets.

@unhammer
Created January 16, 2015 14:33
Show Gist options
  • Select an option

  • Save unhammer/822dfaa2ab91cc577e4b to your computer and use it in GitHub Desktop.

Select an option

Save unhammer/822dfaa2ab91cc577e4b to your computer and use it in GitHub Desktop.
gt-corpus-xmldiff.sh prev-converted/ new-converted/
#!/bin/sh
set -u
c14n_sort ()
{
# The order of <parallel_text> elements does not matter. Assuming
# input has been through c14n, we can just sort those lines.
awk '
/<version>XSLtemplate/{next}
/<parallel_text/ { p[$0]++; seen++; next }
seen { a[NR]=$0; next }
{b[NR]=$0}
END{
for(i in b)print b[i]
n=asorti(p, sorted)
for (i=1; i<=n; i++) {
print sorted[i]
}
for(i in a)print a[i]
}
' | awk '
/<language/ { p[$0]++; seen++; next }
seen { a[NR]=$0; next }
{b[NR]=$0}
END{
for(i in b)print b[i]
n=asorti(p, sorted)
for (i=1; i<=n; i++) {
print sorted[i]
}
for(i in a)print a[i]
}
'
}
c14n_plus () {
xmllint --c14n - | c14n_sort
}
trap 'rm -f "$c14a" "$c14b"' EXIT
c14a=$(mktemp -t xmldiff.XXXXXXXXXX)
c14b=$(mktemp -t xmldiff.XXXXXXXXXX)
c14n_diff () {
c14n_plus < "$1" > "$c14a"
c14n_plus < "$2" > "$c14b"
diff -u -b "$c14a" "$c14b"
#xmldiff -c "$c14a" "$c14b"
}
dir1=$1
dir2=$2
find "$dir1" -type f -print0 |\
while read -r -d '' f; do
#if [[ ! $f = *housing* ]]; then continue; fi
m=$dir2/${f##${dir1}}
if [[ -f $m && -f $f ]]; then
if ! d=$(c14n_diff "$f" "$m"); then
echo "$m"
echo "$d"
echo
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment