Escaping Commas and Spaces in CSV Output?

Started by blue-j, June 28, 2022, 02:56:59 AM

Previous topic - Next topic

blue-j

Is there a switch or method to output CSV (or TSV) where the data could contain commas or spaces?  Some sort of quoted form?  I've tried to figure it out without achieving joy.

Thanks!
-J


StarGeek

The "standard", as much as there is one for CSV files, is to put double quotes around entries with a comma in them, as well as other items such as line feeds.  Double quotes are doubled.

Example:
C:\>exiftool -G1 -a -s -Description y:\!temp\Test4.jpg
[XMP-dc]        Description                     : Comma ,.<-Line Feed.Double Quote Space "

C:\>exiftool -G1 -a -s -Csv -Description y:\!temp\Test4.jpg
SourceFile,XMP-dc:Description
y:/!temp/Test4.jpg,"Comma ,
<-Line Feed
Double Quote Space ""  "


Libre/Open Office will read CSV files correctly, but I recall that there is something that is legal in a CSV file that Excel has never interpreted properly.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

blue-j

Thank you, Mr StarGeek!  However, I do not see how you are requesting the double quotes around the terms in your command...? Please forgive me if I am being insane again. :p

- J

StarGeek

There is only two items in that CSV.  The source file column has the file path.  Then a comma, which is the comma that separates the columns.  Everything after that, including two line feeds, is one cell.

All of this is a single cell.  The first and last quote are the quotes containing the cell.  To include the double quote within the cell on the last line, it gets doubled.
"Comma ,
<-Line Feed
Double Quote Space ""  "


This is the command I used to embed the data
exiftool -E -Description="Comma ,&#x0a;&lt;-Line Feed&#x0a;Double Quote Space &quot; " y:\!temp\Test4.jpg

With regards to Excel, new lines in the cell would cause problems.  See this thread.  I don't know if that is still the case since I don't use Excel.  Libre Office has no problems when there are new lines in a cell.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype