ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: obetz on October 22, 2020, 11:23:49 AM

Title: Find keyword, not substring
Post by: obetz on October 22, 2020, 11:23:49 AM
Hi all,

how can I list all files with a certain keyword, but not keywords containing the desired keyword?

-if "$Keywords =~ /foo/" triggers also on foobar or afoo, but I'm looking only for "foo".

TIA,

Oliver
Title: Re: Find keyword, not substring
Post by: StarGeek on October 22, 2020, 11:42:18 AM
Try this
exiftool -sep "##" -if "$Keywords=~/(##|^)foo($|##)/" /path/to/files/
Title: Re: Find keyword, not substring
Post by: obetz on October 22, 2020, 12:10:05 PM
thanks for the quick help! I'm a bit out of practice, should have found that out on my own...

exiftool -sep "," -if "$Keywords=~/(,|^)foo(,|$)/" is even better because it doesn't restrict the keywords not to contain ##.
Title: Re: Find keyword, not substring
Post by: StarGeek on October 22, 2020, 01:16:45 PM
But of course you have to make sure that your keywords don't include a comma.  I always chose ## because a double hashtag seems to me to be an unlikely part of a keyword, but a comma can show up in something like "Smith, John".

It all depends upon your data set, which you would best know what it contains.  And you're not limited to only 1 or 2 characters.  A longer random string would also work, such as "68eCud8VaB", 8675309, or ETPhoneHome.

Title: Re: Find keyword, not substring
Post by: obetz on October 22, 2020, 01:52:41 PM
correct. I thought that comma is a fixed delimiter but it isn't.