Skip to content

Instantly share code, notes, and snippets.

@whyvez
Created May 9, 2016 23:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whyvez/da20613d7973254841eb5904ce3fcaab to your computer and use it in GitHub Desktop.
Save whyvez/da20613d7973254841eb5904ce3fcaab to your computer and use it in GitHub Desktop.
Converts csv to AWS DynamoDB STX/ETX ASCII delimited format
# 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