25 lines
629 B
Bash
Executable File
25 lines
629 B
Bash
Executable File
#!/bin/bash
|
|
[[ -f "$1" ]] || {
|
|
echo 'Sqlite3NCSV: view sqlite3 DB with ncsv.
|
|
first argument: sqlite3 file
|
|
second, optional argument: table name. If not given, first in schema used.
|
|
If the second argument contains spaces, it is assumed to be a SELECT query.
|
|
'
|
|
exit
|
|
}
|
|
|
|
sqlfile="$1"
|
|
[[ -z "$2" ]] && {
|
|
table=$( sqlite3 "$sqlfile" "SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite%' LIMIT 1;" )
|
|
} || {
|
|
table="$2"
|
|
}
|
|
[[ "$table" = "${table% *}" ]] && {
|
|
query="SELECT * FROM $table;"
|
|
} || {
|
|
query="$table"
|
|
}
|
|
|
|
sqlite3 -header -separator ' ' -nullvalue NA "$sqlfile" "$query" | ncsv
|
|
|