-
-
Save louisdecharson/2fbba9d3edb00c0d05288561443c3b6b to your computer and use it in GitHub Desktop.
Shell script to automatically rename downloaded NBER WP PDFs
This file contains hidden or 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 for NBER working papers (PDFs starting with "w2") and renames them in "Authors - Title (NBER Year)"" format. | |
# Arguments : | |
# $1 = folder to be searched. If left empty, look into Downloads | |
if [ -z $1 ]; then folder="~/Downloads"; else folder="$1"; fi | |
function getMoveCommand { | |
while read data; do | |
curl "http://www.nber.org/papers/${data}.ris" | awk -v folder="${folder}" -v quote="'" -F" - " '{if ($1=="AU") {sub(/,.*/,"",$2); authors=authors", "$2} else if ($1=="TI"){title=$2} else if ($1=="PY") {year=$2} else if ($1=="L1") {gsub(/.*\//,"",$2); file=$2}} END {sub(/^, /,"",authors); print "mv "folder"/"file" "quote""folder"/"authors" - "title" ("year").pdf"quote}' | |
done | |
} | |
find "${folder}" -name "w2[0-9]*.pdf" | sed 's/.pdf//' | awk -F"/" '{print $NF}' | getMoveCommand | bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment