Skip to content

Instantly share code, notes, and snippets.

@joverlee521
Created March 18, 2022 19:12
Show Gist options
  • Save joverlee521/f4dd05784019548a735ab26de4760002 to your computer and use it in GitHub Desktop.
Save joverlee521/f4dd05784019548a735ab26de4760002 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Modified for TSV based on the comment from @paulfitz at
# https://github.com/paulfitz/daff/issues/127#issuecomment-433538271
if [[ -z "$2" ]]; then
echo "Call as foo.tsv foo.sqlite"
exit 1
fi
header=$(head -n1 $1)
header=$(echo $header | sed "s/ /, /g")
header=$(echo $header | sed "s/,/ primary key,/")
echo $header
cat $1 | tail -n +2 | sqlite3 $2 "create table sheet($header);" ".mode tabs" ".import /dev/stdin sheet"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment