Created
January 25, 2019 13:59
-
-
Save AaronDMarasco-VSI/c6079be0affb2652002cdce4879b2b18 to your computer and use it in GitHub Desktop.
Clean up LibreOffice FODP files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# There are many times OpenOffice / LibreOffice will put in useless spans. | |
# What it does: | |
# Finds a span with a style that has the format <capital letter><1 or more digits> | |
# Finds the close tag and then looks to see if the NEXT span has the same style defined | |
# If they match, the first end and the second begin are stripped | |
# (This is why it has to loop repeatedly, a third won't be seen unless a fourth - they | |
# would match as well) | |
[ "$1" == '' ] && echo "No parameters given: try '$0 *' or '$0 *fodp'" | |
for f in "$@"; do | |
[ -f $f ] || { echo "Skipping non-file '$f'"; continue; } | |
[ ${f##*.} == "fodp" ] || { echo "Skipping non-fodp '$f'"; continue; } | |
NEW=1 | |
FIRST=$(stat -c %s $f) | |
echo -n "Processing $f: " | |
while [ $((ORIG-NEW)) -ne 0 ]; do | |
ORIG=$(stat -c %s $f) | |
perl -i -pe 's|<text:span text:style-name="([A-Z]\d+)">([^<]*?)</text:span><text:span text:style-name="\1">([^<]*?)</text:span>|<text:span text:style-name="\1">\2\3</text:span>|g' $f | |
NEW=$(stat -c %s $f) | |
done | |
DELTA=$((FIRST-NEW)) | |
if [ $DELTA -ne 0 ]; then | |
echo "stripped $((FIRST-NEW)) bytes" | |
# git diff --color=always --stat=,1 $f | cut -f2- -d'|' | head -1 | |
else | |
echo "(no change)" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seriously... FODP files change so much when you just hit "save."
Processing Extra_Device_Support_Development.fodp: stripped 34264 bytes