Countries/populate.sh

23 lines
920 B
Bash
Executable file

#!/bin/bash
echo -n '' >tmp-data.txt
# Parse CSV
while read -r line; do
echo $line |
while IFS="," read code_numeric code_alpha2 code_alpha3 itu currency_code currency_name currency_numeric official_name customary_name tld continent capital; do
echo " { $code_alpha2, new($code_alpha2, \"$official_name\", \"$customary_name\", ${itu:-null}, $([[ -z $currency_code ]] && echo null || echo "\"$currency_code\""), ${currency_numeric:-null}, \"$capital\", \"$tld\") }," >>tmp-data.txt
done
done < <(tail -n +2 countrydata.csv)
# Clear current contents
perl -i -0777 -pe 's/^\s+\/\/%SCRIPT START%\n(.*\n)*\s+\/\/%SCRIPT END%$/ \/\/%SCRIPT START%\n \/\/%CONT%\n \/\/%SCRIPT END%/gm;t' src/Nyanbyte.Countries/CountryData.cs
cont=$(cat tmp-data.txt)
sed -i '/\/\/%CONT%/{
s/\/\/%CONT%/\r/g
r tmp-data.txt
}' src/Nyanbyte.Countries/CountryData.cs
rm tmp-data.txt