如何以正确的格式输出CSV查询结果?

时间:2017-11-30 16:16:25

标签: mysql bash csv

我有以下脚本

mysql -uleuser -plepassword -a ledb -e“select dr.order_id,dr.system_name来自tschedule drtv,其中dr.system_name不在(从ca_tmc_site中选择system_name);” > $ baselogdir / $ datelogdir / $ LOGFILENAME

正在提取的csv文件(logfilename.csv)格式不正确

它变得混乱而且只混合了两列,是因为标签还是空格?

1 个答案:

答案 0 :(得分:0)

试试这个:mysql -uleuser -plepassword -a ledb -ss -e "select dr.order_id, dr.system_name from tschedule drtv where dr.system_name not in (select system_name from ca_tmc_site);" | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g” > $baselogdir/$datelogdir/$logfilename