ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: DafOwen on July 07, 2020, 11:05:09 AM

Title: CSV export of single List-type tags values ?
Post by: DafOwen on July 07, 2020, 11:05:09 AM
Is it possible to export (CSV) only some items from a list-type tag ?

My scenario : I have a bunch of jpg files with a certain code in their keywords (IPTC:keywords and/or XMP:Subject) and want to export just this code.
Code starts with IS

I've managed to export XMP:Subject for just those with the code using:
exiftool -csv -XMP:Subject A162-*.jpg > outputCodes.csv -if "$XMP:Subject=~/IS/"


but I want to export just the code, not all values in the list.

So e.g. of what I want in CSV:

SourceFile,Subject
A162-0001.jpg, IS185-012
A162-0002.jpg, IS185-013
A162-0003.jpg, IS185-014

Thanks
Title: Re: CSV export of single List-type tags values ?
Post by: StarGeek on July 07, 2020, 11:42:26 AM
Will you be including other tags in you CSV output other than the IS keywords?
Title: Re: CSV export of single List-type tags values ?
Post by: DafOwen on July 07, 2020, 11:46:08 AM
Have found a way around this by using a different program (Excel + SEARCH/MID functions)

Was looking for just the IS* keyword (+original filename) no other tags no other list items.
Title: Re: CSV export of single List-type tags values ?
Post by: StarGeek on July 07, 2020, 12:16:08 PM
Glad you figured it out.

I would be pretty complex to do in exiftool.  You would need to remove all Subject keywords that didn't match your pattern.  I could be wrong but I don't think this is possible using the basic -csv option (https://exiftool.org/exiftool_pod.html#csv-CSVFILE).  Instead, I think the -p (printFormat) option (https://exiftool.org/exiftool_pod.html#p-FMTFILE-or-STR--printFormat) would need to be used.

This seems to work with my quick test, though it doesn't have column headers.  This would be the command for Windows, Mac/Linux would need different quoting.
exiftool -p """"$Directory#\$filename#""",${subject@;$_=undef if !/^IS/}" /path/to/files/ >file.csv

Other tags could be added to this by using the -api Filter option listed near the end of FAQ #12 (https://exiftool.org/faq.html#Q12).