Skip to content

Instantly share code, notes, and snippets.

@dominykas
Created August 14, 2016 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominykas/d6fcc1ceb36b6fc1231b71385f0bf1c7 to your computer and use it in GitHub Desktop.
Save dominykas/d6fcc1ceb36b6fc1231b71385f0bf1c7 to your computer and use it in GitHub Desktop.
#!/bin/bash
SUFFIX=$(date +%m%d)
BASE_FOLDER="./split-economist-${SUFFIX}"
ISSUES=($(find ~/Downloads/Issue*.zip -type f))
if [[ ${#ISSUES[@]} != 1 ]]; then
echo "Could not find exactly 1 Economist issue zip";
exit 1
fi
ISSUE=${ISSUES[0]}
unzip -q ${ISSUE} -d ${BASE_FOLDER}
FOLDERS=(
"Introduction;Letters;Books and arts;Obituary"
"The world this week;Leaders;Briefing"
"International;Business;Finance and economics"
"Europe;Britain"
"United States;Middle East and Africa"
"The Americas;Asia;China"
"Science and technology"
)
FOLDER=0
IFS=""
for ITEMS in ${FOLDERS[@]}; do
mkdir -p ${BASE_FOLDER}/${FOLDER}
IFS=";"
for CATEGORY in ${ITEMS[@]}; do
find ${BASE_FOLDER} -type f | grep "/[0-9][0-9][0-9] ${CATEGORY}\.mp3" | xargs -I{} rm {}
find ${BASE_FOLDER} -type f | grep "${CATEGORY} - " | while read FILE; do
mv "${FILE}" ${BASE_FOLDER}/${FOLDER}
done
done
FOLDER=$((${FOLDER} + 1))
IFS=""
done
unset IFS
find ${BASE_FOLDER}
ls -al ${BASE_FOLDER}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment