The . that breaks lines in csv file.

Started by JlrJlr, October 04, 2021, 06:07:03 PM

Previous topic - Next topic

JlrJlr


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.


StarGeek

By default, control characters are replaced by a dot in the output unless the -b (-binary) option 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/

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

JlrJlr

Many thanks StarGeek

Your explation is clear and the solution perfect.

My usercoments are clean now.