Created
May 9, 2016 23:25
-
-
Save whyvez/da20613d7973254841eb5904ce3fcaab to your computer and use it in GitHub Desktop.
Converts csv to AWS DynamoDB STX/ETX ASCII delimited format
This file contains hidden or 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
# converts a csv file to a dynamodb compatible stx/etx acsii delimited file | |
# awk -F, -v types=n,s,s,s,s,s,n,n -f csv2dyn.awk mydata.csv > dynamo.txt | |
BEGIN { | |
STX="\02" | |
ETX="\03" | |
split(types, dtypes, ",") | |
} | |
NR == 1 { | |
split($0, columns, FS) | |
} | |
NR > 1 { | |
row="" | |
split($0, values, FS) | |
for (i = 1; i <= NF; i++) { | |
row = row columns[i] ETX "{\"" dtypes[i] "\":\"" values[i] "\"}" | |
if (i < NF) row = row STX | |
} | |
print row | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment