-csv option excludes -ec option ?

Started by wschulte, April 08, 2021, 03:30:12 AM

Previous topic - Next topic

wschulte

In trying to extract fields to a CSV file I stumbled on some fields containing newlines. Like in the next example:
~/tmp$ exiftool -csv -exif:usercomment -iptc:caption-abstract Untitled.jpg
SourceFile,UserComment,Caption-Abstract
Untitled.jpg,"Règél
âççent","Abstract regel 1
Abstract regel 2
Abstract regel 3"


Having dealt with this problem before I tried to use the conversion to C style control (-ec) but that doesn't seem to work with csv:
~/tmp$ exiftool -ec -csv -exif:usercomment -iptc:caption-abstract Untitled.jpg
SourceFile,UserComment,Caption-Abstract
Untitled.jpg,"Règél
âççent","Abstract regel 1
Abstract regel 2
Abstract regel 3"


I can't figure out what I am doing wrong. The -ec option works normally just fine:
~/tmp$ exiftool -ec -exif:usercomment -iptc:caption-abstract Untitled.jpg
User Comment                    : Règél\nâççent
Caption-Abstract                : Abstract regel 1\nAbstract regel 2\nAbstract regel 3


Can anybody help ?

Luuk2005

Im thinking its better to not counterfeit the output, because exiftool needs this format when writing tags from the csv.
But if just for the eyesight, there is always -api "Filter=s/\n/--YourReplacement--/g" to make it look better????
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

wschulte

Quote from: Luuk2005 on April 08, 2021, 05:06:11 AM
Im thinking its better to not counterfeit the output, because exiftool needs this format when writing tags from the csv.
But if just for the eyesight, there is always -api "Filter=s/\n/--YourReplacement--/g" to make it look better????

@Luuk2005. Thanks for that one, I should have thought of it myself. Works as a charm. What I needed it for was importing it to the database (ic. MySQL) and as newline is standard the record separator in CSV I assumed it would go wrong, so I would have to replace it.
To my total surprise it was unnecessary. Even with the newlines in it, importing it with a LOAD statement worked (probably because all columns were named) ! Even more surprised: viewing the CSV in LibreOfficeCalc worked.
So in fact I didn't need it, just a plain CSV works.

Phil Harvey

Quote from: wschulte on April 08, 2021, 07:31:12 AM
So in fact I didn't need it, just a plain CSV works.

Yes.  Newlines are allowed in quoted CSV entries, and should be accepted by any reasonable CSV reader.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).