-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script that will create JSON files for each record
Toward #1.
- Loading branch information
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
api/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# The source CSV file. | ||
SOURCE_DATA=united-states.csv | ||
|
||
# Where we want our JSON files to go. | ||
OUTPUT_DIR=./api | ||
|
||
# Create the JSON directory. | ||
mkdir -p "$OUTPUT_DIR" | ||
|
||
# Iterate through each line in the CSV file. | ||
while read -r p; do | ||
FIPS_VALUE=$(echo "$p" | cut -d "," -f 1) | ||
GNIS_VALUE=$(echo "$p" | cut -d "," -f 2) | ||
OUTPUT_FILE="$OUTPUT_DIR"/"$FIPS_VALUE".json | ||
echo "{\"fips\":\"$FIPS_VALUE\",\"gnis\":\"$GNIS_VALUE\"}" > "$OUTPUT_FILE" | ||
done <$SOURCE_DATA |