Created
December 14, 2016 13:35
-
-
Save t27/bf68fdcea3bb4213cdbcb3397b9a886c to your computer and use it in GitHub Desktop.
Bash script to find all pdf files in a folder and subfolders, use the unix 'file' command to check its actual type and rename to .epub or .html accordingly (used for renaming glitchy google play books takeout 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
EPUBSTR="EPUB document" | |
HTMLSTR="XML document text" | |
for f in */*.pdf | |
do | |
VAR1=$(file -b "$f") | |
# echo $VAR1 | |
if [[ "$VAR1" == "$EPUBSTR" ]]; | |
then | |
fnew=${f/%.pdf/.epub} | |
mv "$f" "$fnew" | |
elif [[ "$VAR1" == "$HTMLSTR" ]]; | |
then | |
fnew2=${f/%.pdf/.html} | |
mv "$f" "$fnew2" | |
else | |
echo "Not an epub" | |
fi | |
# do something on $f | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment