Skip to content

Instantly share code, notes, and snippets.

@eosBlockSmith
Last active June 4, 2019 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eosBlockSmith/2e94f1777ad369f5a0e38f6d9ed23547 to your computer and use it in GitHub Desktop.
Save eosBlockSmith/2e94f1777ad369f5a0e38f6d9ed23547 to your computer and use it in GitHub Desktop.
Parse Country Codes, Write JSON Array
@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
@eosBlockSmith
Copy link
Author

eosBlockSmith commented Jun 4, 2019

Thrown together for one-time use. Used particularly in the Worbli Testnet Portal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment