sqlite3ncsv to view dbs

This commit is contained in:
q
2014-07-20 19:21:54 +03:00
parent ae80789ad1
commit 9144e89a9e
2 changed files with 24 additions and 0 deletions

1
bin/sqlite3ncsv Symbolic link
View File

@@ -0,0 +1 @@
../sqlite3ncsv

23
sqlite3ncsv Executable file
View File

@@ -0,0 +1,23 @@
#!/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
}
[[ -z "$2" ]] && {
table=$( sqlite3 "$1" "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 "$1" "$query" | ncsv