The answers above don't seem to fully answer the original question, and I'm not sure if this does either, but hopefully this might help someone:
See How to output MySQL query results in CSV format? for a lot of comments regarding how to sed
. For example, based on the original parameters, the following might be sufficient:
mysql --batch -u user -h remote.host.tld database --port 3306 -ppass -e "SELECT * FROM webrecord_wr25mfz_20101011_175524;" | sed 's/\t/,/g' 2>&1
This is similar to the answer above, but redirecting to stdout
instead of blah.csv
.
However, (although not sure if this will work if you need to preserve tabs, there are many ways to address this though), I've used https://mcmap.net/q/334611/-fastest-way-convert-tab-delimited-file-to-csv-in-linux to correctly escape double quotations and convert to comma-separated:
mysql --batch -u user -h remote.host.tld database --port 3306 -ppass -e "SELECT * FROM webrecord_wr25mfz_20101011_175524;" | perl -lpe 's/"/\\"/g; s/^|$/"/g; s/\t/","/g' 2>&1
- Execute the
sql
"SELECT * FROM webrecord_wr25mfz_20101011_175524;"
via mysql
(this output will be tab-separated)
- Convert to comma-separated by piping to
perl -lpe 's/"/\\"/g; s/^|$/"/g; s/\t/","/g'
- Have the output go to
stdout
by appending 2>&1