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,col3\na,1,2.6\nb,2,5.4\n" | ./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
.import /dev/stdin $table_namework? (Depending on your OS, you might need to replace/dev/stdinwith/dev/fd/0or something like that.)/dev/stdinwould work, but I wanted to avoid referring to files that might be non-standard./dev/stdinor a temporary named pipe.sqliteprocess accessing the file, notbash, there is no guarantee about/dev/stdinexisting (although, there is very few systems that does not have it).