Skip to content

Instantly share code, notes, and snippets.

@anjesh
Last active August 29, 2015 14:00
Show Gist options
  • Save anjesh/11029530 to your computer and use it in GitHub Desktop.
Save anjesh/11029530 to your computer and use it in GitHub Desktop.
# csvfix to be installed
# All CRS projects zip files available at http://stats.oecd.org/Index.aspx?datasetcode=CRS1# export > related files
# here 2011 is used as an example, for other years, you have to update the command content below
wget "http://stats.oecd.org/FileView2.aspx?IDFile=d79d2d4e-f15a-41de-83f8-b61a8f5c227a" -O CRS-2011.zip
unzip CRS-2011.zip
# there's some binary characters which needs to be removed before transformation
tr -cd '\11\12\15\40-\176' < "CRS 2011 data.txt" > clean-crs-2011.txt
#CRS 2011 data.txt file gets created after unzip, removing it for clarity. You don't need this file once you have the clean one
rm "CRS 2011 data.txt"
# write the header first
csvfix head -sep "|" -n 1 clean-crs-2011.txt > crs-nepal-2011.csv
#filter the file by recipient-country (column 10 in the file) and "|" is used as separator
csvfix find -e "Nepal" -f 10 -sep "|" clean-crs-2011.txt >> crs-nepal-2011.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment