Skip to content

Instantly share code, notes, and snippets.

@toddbranch
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save toddbranch/21d49f929bda5a56fb8b to your computer and use it in GitHub Desktop.

Select an option

Save toddbranch/21d49f929bda5a56fb8b to your computer and use it in GitHub Desktop.
Yankees Best / Worst
#!/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
@toddbranch

Copy link
Copy Markdown
Author

Edit: Making it multi-threaded makes it run in about half the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment