Skip to content

Instantly share code, notes, and snippets.

@log4code
Last active Feb 4, 2021
Embed
What would you like to do?
Convert a CSV file to a Markdown table using SQLite3
#!/bin/bash
#remove old output fiile
outputFile="$1.md"
rm -f outputFile
#SQLite3 commands
cmd=$({ grep -v '^#' <<EOF
.headers on
.mode csv
drop table if exists temp_csvFile;
.import $1 temp_csvFile
.mode markdown
.headers on
.output $outputFile
select * from temp_csvFile;
EOF
})
#Pipe commands to temporary database
echo -e "$cmd" | sqlite3 ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment