Skip to content

Instantly share code, notes, and snippets.

@log4code
Last active January 1, 2023 23:09
Show Gist options
  • Save log4code/079d1d1f02ea2c766951b220ce5b23f5 to your computer and use it in GitHub Desktop.
Save log4code/079d1d1f02ea2c766951b220ce5b23f5 to your computer and use it in GitHub Desktop.
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