Skip to content

Instantly share code, notes, and snippets.

Created July 28, 2013 18:43
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mindbat/6099596 to your computer and use it in GitHub Desktop.
Bash script to rename project gutenberg ebooks to their document titles.
# Bash script to pull document titles from
# Project Gutenberg ebooks.
# Invoke using command like:
# find ./ -type f -name "*.txt" | xargs -n 1 ./ ~/Documents/
# pull the first line of the file
FIRST_LINE=`head -n 1 $2`
# find the title
TITLE=${FIRST_LINE#"The Project Gutenberg Etext of "}
TITLE=${TITLE#"The Project Gutenberg EBook of "}
TITLE=${TITLE#"The Project Gutenberg ebook "}
TITLE=${TITLE#"The Project Gutenberg eBook, "}
TITLE=${TITLE#"Project Gutenberg's "}
TITLE=${TITLE#"Project Gutenberg Etext "}
TITLE=${TITLE#"The Project Gutenberg Etext, "}
TITLE=${TITLE#"Project Gutenberg Etext, "}
# standardize the title
# cp the file to the new filename
cp $2 $NEWFILE
mv $NEWFILE $1
# exit 0
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment