Skip to content

Instantly share code, notes, and snippets.

@slwu89
Last active August 29, 2017 01:17
Show Gist options
  • Save slwu89/0a4ecb658dc8fc83c26583c12b874757 to your computer and use it in GitHub Desktop.
Save slwu89/0a4ecb658dc8fc83c26583c12b874757 to your computer and use it in GitHub Desktop.
stat243-ps1.txt
# 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