Last active
August 29, 2017 01:17
-
-
Save slwu89/0a4ecb658dc8fc83c26583c12b874757 to your computer and use it in GitHub Desktop.
stat243-ps1.txt
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
# download the data | |
wget -O apricots.zip "http://data.un.org/Handlers/DownloadHandler.ashx?DataFilter=itemCode:526&DataMartId=FAO&Format=csv&c=2,3,4,5,6,7&s=countryName:asc,elementCode:asc,year:desc" | |
unzip -p apricots.zip > apricots.csv | |
# split into region and country | |
grep -v "+" apricots.csv > countries.csv | |
grep "+" apricots.csv > regions.csv | |
# put all the 2005 data to a new countries05.csv file | |
awk -F "\"*,\"*" '$4 == 2005 ' countries.csv > countries05.csv | |
# find out the which countries harvested the most | |
grep -i 'Area Harvested' countries05.csv | sort -t',' -n -k6 -r | head -5 | |
# automate it | |
for var in $(seq 1965 10 2005) | |
do | |
echo $var | |
grep -i -e ${var} countries.csv | grep -i 'Area Harvested' | sort -t',' -n -k6 -r | head -5 > top${var}.txt | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment