Last active
June 4, 2019 15:09
-
-
Save eosBlockSmith/2e94f1777ad369f5a0e38f6d9ed23547 to your computer and use it in GitHub Desktop.
Parse Country Codes, Write JSON Array
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
@ECHO OFF | |
REM http://download.geonames.org/export/dump/countryInfo.txt | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
SET "sourcedir=C:\Users\Caleb\Desktop\country_codes" | |
SET "tab= " | |
CALL :find_data | |
GOTO :eof | |
:find_data | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
ECHO [>%sourcedir%\output.txt | |
FOR /F "delims=" %%T IN (%sourcedir%\input.txt) DO ( | |
SET "dataline=%%T" | |
SET "dataline="!dataline:%tab%="#"!"" | |
FOR /f "tokens=1,2,3,5 delims=#" %%a IN ("!dataline!") DO ( | |
SET alpha2=%%~a | |
SET alpha3=%%~b | |
SET numeric=%%~c | |
SET country=%%~d | |
ECHO [!alpha2!] [!alpha3!] [!numeric!] [!country!] | |
ECHO { alpha2: "!alpha2!", alpha3: "!alpha3!", numeric: "!numeric!", country: "!country!" }>>%sourcedir%\output.txt | |
) | |
) | |
ECHO ]>>%sourcedir%\output.txt | |
REM flags at https://www.countryflags.io | |
ENDLOCAL | |
GOTO :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thrown together for one-time use. Used particularly in the Worbli Testnet Portal.