ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: JlrJlr on October 04, 2021, 06:07:03 PM

Title: The . that breaks lines in csv file.
Post by: JlrJlr on October 04, 2021, 06:07:03 PM

I am doing csv extraction of a large number of photos. For a few photos I notice unexpected line breaks in csv file.
The culprit turn to be photos with a single point in "UserComment".

here is a sample of a broken csv with 2 photos


exiftool -UserComment -csv

the csv file

SourceFile,UserComment
cha_55.jpg,.
Cha_93.jpg,"
"



Cha_55.jpg is ok. It is a photo where I put the . myself with exiftool
cha_93.jpg is a problematic file, I do not know how the . was introduced.
In this case, in the csv the . is replaced by LF enclosed in "".


The display in exiftool looks good, the 2 points look the same


exiftool -UserComment 
======== cha_55.jpg
User Comment                    : .
======== Cha_93.jpg
User Comment                    : .



But the filter (I want to erase all UserComment  with a single .) does not work.
Only the point of cha_55.jpg is recognized. Note that a regexp gives the same result.


Exiftool  -if "$UserComment eq '.'" -UserComment 

======== cha_55.jpg
User Comment                  : .
    1 files failed condition
    1 image files read


Thank you for an advice on how to  erase "User Comment" containing the csv breaking point.

Title: Re: The . that breaks lines in csv file.
Post by: StarGeek on October 04, 2021, 06:31:23 PM
By default, control characters are replaced by a dot in the output unless the -b (-binary) option (https://exiftool.org/exiftool_pod.html#b---b--binary---binary) is used.  But the character is still the control character.

For your command, try this. In this case, the double quotes need to be escaped on the command line because single quotes won't convert \n into a new line
exiftool  -if "$UserComment eq \"\n\"" -UserComment /path/to/files/

Or using regex
exiftool -if "$UserComment=~/^\n$$/" -UserComment /path/to/files/

Finally, to catch all cases of one or more white spaces, including spaces, line feeds, carriage returns, and tabs
exiftool -if "$UserComment=~/^\s+$$/" -UserComment /path/to/files/

Title: Re: The . that breaks lines in csv file.
Post by: JlrJlr on October 05, 2021, 05:49:55 AM
Many thanks StarGeek

Your explation is clear and the solution perfect.

My usercoments are clean now.