Skip to content

Instantly share code, notes, and snippets.

@jrha
Created March 7, 2013 08:20
Show Gist options
  • Save jrha/5106420 to your computer and use it in GitHub Desktop.
Save jrha/5106420 to your computer and use it in GitHub Desktop.
Find and group differences between two XML trees.
#!/bin/bash
if [[ -f "/usr/bin/shasum" ]]; then
SHASUM='/usr/bin/shasum'
else SHASUM='/usr/bin/sha1sum'
fi
if [[ -n "$XML1" ]] && [[ -n "$XML2" ]] && [[ "$XML1" != "$XML2" ]]; then
profiles=$(diff $XML1 $XML2 --brief | grep -v '\.dep' | grep -v '\.json\.gz' | grep -v profiles-info.xml | grep -v "Only in" | awk '{ print $2 }' | sed "s/^.*\///g")
count=0
for p in $profiles; do
count=$(($count + 1))
done
pos=0
echo -n "Examining profiles, please wait " 1>&2
exemplars="$(for p in $profiles; do
pos=$(($pos + 1))
echo -n "$p: "
perc="$((($pos * 100) / $count))"
perc=$(printf "%3i%%" $perc)
echo -en "\b\b\b\b$perc" 1>&2
diff -w $XML1/$p $XML2/$p | grep -v "^[0-9]" | sort | $SHASUM
done | rev | sort | rev | uniq -f 1 -c | cut -d : -f 1 | awk '{ print $2","$1 }')"
echo "Completed."
for x in $exemplars; do
p=$(echo $x | cut -d , -f 1)
n=$(echo $x | cut -d , -f 2)
echo "---- $p (exemplar for $n profiles) ----"
colordiff -w $XML2/$p $XML1/$p $@
done
else
echo "Please set environment variables XML1 and XML2 to point to the locations of two different XML trees."
echo "XML1=$XML1"
echo "XML2=$XML2"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment