Dan, I'd recommend using a tool that actually understands CSV, and make it parse the input and create new quoted output. I haven't seen your sed and awk, but I'm pretty sure it's easy to find some special cases where the text includes comma, quotes or even newlines that will break your output.
A simple stab at what I think you need would be something like this python3 script: $ cat quotecsv.py #!/usr/bin/env python3 import csv import sys csv_in = csv.reader(sys.stdin, delimiter=',', quotechar='"') csv_out = csv.writer(sys.stdout, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) for row in csv_in: csv_out.writerow(row) ### That's it ### Then you can pipe some csv through this, here's a sample line where fields are only quoted where necessary, and the result after piping through the python script: $ echo 'a,b,c,"d e","f, g"' a,b,c,"d e","f, g" $ echo 'a,b,c,"d e","f, g"' | ./quotecsv.py "a","b","c","d e","f, g" Cheers, Ketil On 14 June 2017 at 07:46, <d...@dan.bz> wrote: > Thanks Richard, in the end I added the quotes using some SED and AWK as I'm > using SQLite as part of a BASH script. > > Thanks > > > On 2017-06-13 14:36, Richard Hipp wrote: >> >> SQLite does not provide that capability, that I recall. >> >> But surely it would not be too difficult for you to do your own custom >> patch, or even to write a short program to output the data in the >> precise format you desire? >> >> On 6/12/17, d...@dan.bz <d...@dan.bz> wrote: >>> >>> Hi, >>> >>> When outputting to CSV with '.mode csv' is there a way that all rows can >>> be quoted even if there are no spaces? For example, here is a 1 line >>> from the output: >>> >>> spotify:track:5vlDIGBTQmlyfERBnJOnbJ,Kiso,Circles,100.019 >>> >>> I would like it to output: >>> >>> "spotify:track:5vlDIGBTQmlyfERBnJOnbJ","Kiso","Circles",100.019 >>> >>> Thanks! >>> _______________________________________________ >>> sqlite-users mailing list >>> sqlite-users@mailinglists.sqlite.org >>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users >>> > > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users -- -Ketil _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users