How would you modify function csv_to_sqlite
so that sqlite3
command .import
reads directly from standard input instead of from a temporary named pipe?
#!/bin/bash
function csv_to_sqlite() {
local database_file_name="$1"
local table_name="$2"
local temp_input_fifo=$(mktemp -u)
mkfifo $temp_input_fifo
sqlite3 -csv $database_file_name ".import $temp_input_fifo $table_name" &
cat > $temp_input_fifo
rm $temp_input_fifo
}
database_file_name=$1
table_name=$2
csv_to_sqlite "$database_file_name" "$table_name"
$ printf "col1,col2,col3na,1,2.6nb,2,5.4n" | ./csv_to_sqlite test.sqlite test
$ sqlite3 -csv -header test.sqlite "SELECT * FROM test"
col1,col2,col3
a,1,2.6
b,2,5.4