Skip to content

Instantly share code, notes, and snippets.

@kidmose
Created August 16, 2017 09:16
Show Gist options
  • Save kidmose/a3b8c05f062041375dec3bd72402fdcd to your computer and use it in GitHub Desktop.
Save kidmose/a3b8c05f062041375dec3bd72402fdcd to your computer and use it in GitHub Desktop.
Convert any file or dir to something printable, and wrap it in some (wacky) XML.
#!/bin/bash
# Convert any file or dir to something printable, and wrap it in some (wacky) XML.
#
# Usage example:
# find . -exec ./printer.sh {} \; > out.txt
FILE=$1
TYPE=$(file -b $FILE)
if [[ "$TYPE" == "directory" ]]; then
echo "<directory path=\"$FILE\" />"
elif [[ "$TYPE" == *"text"* ]]; then
echo "<file path=\"$FILE\" type=\"$TYPE\">"
cat $FILE
echo "</file>"
else
echo "<binary path=\"$FILE\">"
xxd $FILE
echo "</binary>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment