Created
September 25, 2019 16:18
-
-
Save mikegerber/d6b4aae43ef606968f4f3d48ef168f39 to your computer and use it in GitHub Desktop.
Fix mets.xml for easy cases
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/sh | |
# Fix mets.xml for easy cases | |
xmlstarlet sel -N mets=http://www.loc.gov/METS/ -t -m "//mets:FLocat" -v "@xlink:href" -n mets.xml | while read f; do | |
if echo "$f" | grep -q "^http://"; then | |
continue | |
fi | |
if [ ! -e $f ]; then | |
echo "$f does not exist" | |
for try_ext in .xml .tif; do | |
try_f="$f$try_ext" | |
if [ -e "$try_f" ]; then | |
echo "💡 but $try_f exists, fixing" | |
xmlstarlet ed --inplace -N mets=http://www.loc.gov/METS/ --update "//mets:FLocat[@xlink:href='$f']/@xlink:href" --value "$try_f" mets.xml | |
fi | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment