Skip to content

Instantly share code, notes, and snippets.

@mindbat
Created July 28, 2013 18:43
Embed
What would you like to do?
Bash script to rename project gutenberg ebooks to their document titles.
#!/bin/bash
# Bash script to pull document titles from
# Project Gutenberg ebooks.
# Invoke using command like:
# find ./ -type f -name "*.txt" | xargs -n 1 ./process.sh ~/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
STANDARD=${TITLE// /-}
STANDARD=${STANDARD%?}
NEWFILE=$STANDARD".txt"
# 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