sqlite3ncsv to view dbs
This commit is contained in:
23
sqlite3ncsv
Executable file
23
sqlite3ncsv
Executable 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
|
||||
|
||||
Reference in New Issue
Block a user