Created
January 25, 2019 00:57
-
-
Save jdingel/4a4c17a1e023b1845cfc5ec83449ebc3 to your computer and use it in GitHub Desktop.
Shell script to rename AEA journal article PDFs
This file contains 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
#!/bin/bash | |
#This script searches the Downloads folder for AEA journal articles and renames them in "Author - Title (journal Year)" format. | |
#On Mac OS X, you can't use \| in a basic regular expression, which is what "find" uses by default. | |
cd ~/Downloads | |
articles=$(find . -name "[ajmp][aeipo][clpr].[0-9]*.pdf" | sed 's/^.\//\ /' | sed 's/.pdf//' | tr -d '\n') | |
echo "$articles" | |
for article in $articles | |
do | |
curl "https://www.aeaweb.org/articles/citation-export?args%5Bformat%5D=ris&args%5Bdoi%5D=10.1257%2F$article&args%5Btype%5D=ris" > temp.txt | |
authors=$(grep 'AU' temp.txt | sed 's/^AU - \([A-Za-zÀ-ÿş]*,\ \).*$/\1/' | tr -d '\n' | sed 's/,\ $//') | |
title=$(grep 'T1' temp.txt | sed 's/^T1 - //' | sed 's/:/ -/' | sed 's/.$//') | |
journal=$(echo $article | sed 's/^\([a-z]*\)\..*/\1/' | sed 's/aer/AER/' | sed 's/jel/JEL/' | sed 's/jep/JEP/' | sed 's/app/AEJA/' | sed 's/pol/AEJEP/' | sed 's/mic/AEJ Micro/' | sed 's/mac/AEJ Macro/') | |
year=$(grep 'PY' temp.txt | awk -F- '{print $2}' | sed 's/.$//') | |
newname="$authors - $title ($journal$year).pdf" | |
if [ "$(echo $newname | wc -c)" -ge 15 ]; then mv $article.pdf "$newname" ; fi | |
rm temp.txt | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment