Improve diff-docx.sh -> diff-zip.sh.
It now can be used on odts, docx, or epubs.
This commit is contained in:
parent
2c2d4e2138
commit
83a0104d5b
2 changed files with 26 additions and 22 deletions
|
@ -1,22 +0,0 @@
|
|||
#!/bin/sh
|
||||
f1="$1"
|
||||
f2="$2"
|
||||
test -f "$f1" -a -f "$f2" || {
|
||||
echo "Usage: diff-docx first.docx second.docx" && exit 1
|
||||
}
|
||||
WORKDIR=$(mktemp -d -t diff-docx)
|
||||
trap "{ rm -r $WORKDIR; }" EXIT
|
||||
unzip -q -d "$WORKDIR/a" "$f1"
|
||||
unzip -q -d "$WORKDIR/b" "$f2"
|
||||
cd "$WORKDIR"
|
||||
mkdir tidy
|
||||
for x in a b; do
|
||||
cp -r $x tidy/
|
||||
find $x -iname '*.xml' -exec sh -c 'mkdir -p "$(dirname tidy/$1)" && tidy -q -xml -utf8 -i "$1" > "tidy/$1"' _ {} \;
|
||||
find $x -iname '*.rels' -exec sh -c 'mkdir -p "$(dirname tidy/$1)" && tidy -q -xml -utf8 -i "$1" > "tidy/$1"' _ {} \;
|
||||
done
|
||||
cd tidy
|
||||
mkdir c
|
||||
cp -r a/* c/
|
||||
cp -r b/* c/
|
||||
find c -type f -exec sh -c 'echo "\033[1m=== ${1#*/} ===\033[0m" ; diff -u "a/${1#*/}" "b/${1#*/}" 2>&1' _ {} \;
|
26
tools/diff-zip.sh
Executable file
26
tools/diff-zip.sh
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script allows you to compare two epub, odt, or docx
|
||||
# containers, ignoring insignificant formatting differences
|
||||
# in the XML contents.
|
||||
|
||||
f1="$1"
|
||||
f2="$2"
|
||||
test -f "$f1" -a -f "$f2" || {
|
||||
echo "Usage: diff-zip firstfile secondfile" && exit 1
|
||||
}
|
||||
WORKDIR=$(mktemp -d -t diff-zip)
|
||||
trap "{ rm -r $WORKDIR; }" EXIT
|
||||
unzip -q -d "$WORKDIR/a" "$f1"
|
||||
unzip -q -d "$WORKDIR/b" "$f2"
|
||||
cd "$WORKDIR"
|
||||
mkdir tidy
|
||||
for x in a b; do
|
||||
cp -r $x tidy/
|
||||
find -E $x -iregex '.*\.(xhtml|xml|rdf|rels)' -exec sh -c 'mkdir -p "$(dirname tidy/$1)" && tidy -q -xml -utf8 -i "$1" > "tidy/$1"' _ {} \;
|
||||
done
|
||||
cd tidy
|
||||
mkdir c
|
||||
cp -r a/* c/
|
||||
cp -r b/* c/
|
||||
find c -type f -exec sh -c 'echo "\033[1m=== ${1#*/} ===\033[0m" ; diff -u "a/${1#*/}" "b/${1#*/}" 2>&1' _ {} \;
|
Loading…
Add table
Reference in a new issue