Last active
August 29, 2015 14:19
-
-
Save toddbranch/21d49f929bda5a56fb8b to your computer and use it in GitHub Desktop.
Yankees Best / Worst
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
| #!/usr/bin/bash | |
| START_TIME=$SECONDS | |
| # erase file so it can be re-run | |
| > results.txt | |
| get_record() { | |
| record=$(curl --silent http://www.baseball-reference.com/teams/NYY/$1.shtml | ack -o 'content="\d+-\d+' | sed s/content=\"//g | uniq) | |
| echo "$i: $record" >> results.txt | |
| } | |
| for i in {1901..2014} | |
| do | |
| get_record $i & | |
| done | |
| wait | |
| echo -e "Best Seasons" | |
| cat results.txt | sed '/ $/d' | sort -t"-" -k2 -n | head -5 | |
| echo -e "\nWorst Seasons" | |
| cat results.txt | sort -t"-" -k2 -n | tail -5 | |
| ELAPSED_TIME=$(($SECONDS - $START_TIME)) | |
| echo $ELAPSED_TIME |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit: Making it multi-threaded makes it run in about half the time.