Skip to content

Instantly share code, notes, and snippets.

@malesch
Created September 18, 2011 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malesch/1225683 to your computer and use it in GitHub Desktop.
Save malesch/1225683 to your computer and use it in GitHub Desktop.
XML formatter (glob aware)
#!/bin/bash
if [ $# == 0 ]
then
echo "Usage: xmlformat <file selector>"
echo "Examples: xmlformat test.xml"
echo " xmlformat foo*.xml"
fi
for filename in $*
do
# echo "file extension is ${filename#*.}"
if ([ -f ${filename} ] && [ ${filename#*.} == "xml" ])
then
TFILE=`mktemp`
xmllint --format ${filename} > ${TFILE}
mv ${TFILE} ${filename}
else
echo "Ignoring ${filename} because not an XML file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment