ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Lagrandeimage on December 12, 2020, 06:53:29 PM

Title: How to count number of files with two specific keywords?
Post by: Lagrandeimage on December 12, 2020, 06:53:29 PM
Hello,

I would like to count the number of files who contain two specific keywords.

Added difficulty: one of the keywords is identical to the other part from accented characters  => Bérénice and B?r?nice.

The next step will probably be to delete B?r?nice (If as I suspect the two keywords are present in the same files), I would use :

exiftool -subject-=B?r?nice -r DIR

But that would delete the Bérénice as well no? How to make the "?" be treated as normal character?

Thanks in advance,

Cheers.
Title: Re: How to count number of files with two specific keywords?
Post by: Phil Harvey on December 12, 2020, 08:59:02 PM
Question marks are not special in the -= argument.  They are treated as any other character.

- Phil
Title: Re: How to count number of files with two specific keywords?
Post by: Lagrandeimage on December 15, 2020, 02:59:41 PM
Great thanks Phil, that settles a part of the problem.

Is there a solution for counting the  number of files where both Bérénice and B?r?nice are set?
Title: Re: How to count number of files with two specific keywords?
Post by: Luuk2005 on December 16, 2020, 06:09:58 AM
Greetings Lagrandeimage, if on Windows it can be like ...
exiftool -q -if "$keywords =~ /\bWord1\b/i and $keywords = ~/\bWord2\b/i" -p "$filepath" "YourFolderPath" |findstr /N "^"
This to present all the filepaths, with a number in the front.

If on Linux, it can be like ...
exiftool -q -if '$keywords =~ /(?=.*\bWord1\b)(?=.*\bWord2\b)/i' -p '$filename' 'YourFolderPath' |sed -n '$='
This to only count the files, not showing any names or paths.

If Word1 and Word2 must be case-sensitive matching, please to destroy i after the /regexes/.
Title: Re: How to count number of files with two specific keywords?
Post by: StarGeek on December 16, 2020, 10:56:17 AM
Note that this will also match keywords that contain the indicated word.  And since an apostrophe is considered a word boundry, using the above to search for Bérénice would also match Bérénice's daughter, as well as any keyword that contains Bérénice as a separate word.

Also, sed isn't available on Windows unless you install a ported version.

Try this if you want to match the keyword exactly (change double quotes to single if on Mac/Linux)
exiftool -sep "##" -if "$Subject=~m/(?:##|^)Bérénice(?:$|##)/ and $Subject=~m/(?:##|^)B?r?nice(?:$|##)/" -subject /path/to/files/

I use the -sep option (https://exiftool.org/exiftool_pod.html#sep-STR--separator) with an unlikely character combination because the default comma separator would split a keyword of "Smith, John"
Title: Re: How to count number of files with two specific keywords?
Post by: Luuk2005 on December 16, 2020, 04:37:06 PM
Yes, Im liking the ##-separator much better, because it lets you also search for \b chars in the keywords!
You can even use something crazy like "###||###" if its really to be needed. Many thanks, StarGeek!

So with Windows, it can be like ...
exiftool -q -sep "##" -if "$subject=~/(^|##)Word1(##|$)/i and $subject=~/(^|##)Word2(##|$)/i" -p "$filepath" "YourFolderPath" |findstr /N "^"
This to present all the filepaths, with a number in the front.

If on Linux, it can be like ...
exiftool -q -sep '##' -if '$subject=~/(?=(^|.*##)Word1(##|$))(?=(^|.*##)Word2(##|$))/i' -p '$filename' 'YourFolderPath' |sed -n '$='
This to only count the files, not show any names or paths.

If Word1 and Word2 must be case sensitive match, please to destroy i after the /regexes/.
There is also ways to only show total count# in Windows, but its much longer commands.
Title: Re: How to count number of files with two specific keywords?
Post by: Lagrandeimage on December 22, 2020, 07:13:31 PM
Great, thanks a lot to both of you guys !