Skip to content

Instantly share code, notes, and snippets.

@GrahamWalters
Created November 10, 2017 05:24
Show Gist options
  • Save GrahamWalters/33545334b7d38ce492aa20fbb4d58353 to your computer and use it in GitHub Desktop.
Save GrahamWalters/33545334b7d38ce492aa20fbb4d58353 to your computer and use it in GitHub Desktop.
Packt.epub rename
#!/bin/bash
get_title () {
attr='title'
fileloc=`unzip -l "$1" | ggrep -Po '\b[^\s-]*\.opf\b'`
metafound=`zipgrep '<dc:'$attr'(.+)>(.+)</dc:'$attr'>' "$1" $fileloc`
echo `expr "$metafound" : '.*<dc:'$attr'.*>\(.*\)</dc:'$attr'>.*'`
}
for file in $(find . -type f -depth 1 -name "*.epub"); do
filename=$(get_title "$file")
mv "$file" "Packt - $filename.epub"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment