Skip to content

Instantly share code, notes, and snippets.

View louisdecharson's full-sized avatar
🎯
Focusing

Louis de Charsonville louisdecharson

🎯
Focusing
View GitHub Profile
@louisdecharson
louisdecharson / NBERwp_rename.sh
Last active January 25, 2019 00:59 — forked from jdingel/NBERwp_rename.sh
Shell script to automatically rename downloaded NBER WP PDFs
#!/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
}