delete all xmp keywords except for those specified

Started by Yalkov, December 07, 2021, 06:08:03 AM

Previous topic - Next topic

Yalkov

I want to delete all xmp:subject keywords except those specified. I was unable to figure it out from the examples here https://exiftool.org/exiftool_pod.html#WRITING-EXAMPLES

Can someone please provide an example command to do this?

If it matters, I will be using this command in an argument file.

StarGeek

Please do not make duplicate posts.

Your question was answered here.  Clear the subject then add your specified keywords back in without using -=/+=.
* 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).

Yalkov

#2
Hi,

I did not think it was a duplicate post, sorry, maybe I didn't get it across well or I do not understand.  I want to KEEP an existing set of keywords, but remove ALL OTHERS. I do not know what keywords are in the file already.

The problem is that a file may have one of 50 important keywords to keep, but I do not know without reading them ahead of time which of the 50 are actually in the file. I hope this makes sense...
I also have no idea what other keywords might exist in the same file. I do not want to add all 50 of the important keywords, just the keywords that the file already had (which I do not know ahead of time), and delete everything else.

The other post was about adding new keywords regardless of whatever keywords existed by first deleting all existing keywords. So I did not care about preservation of existing keywords in that case.

If it still is a duplicate I do not understand but would still appreciate help!  :'(

StarGeek

Ok, that's a much more complex operation and the command will be quite long with a list of 50 keywords.

You would want to use a command similar to this post except you would use $_=undef if not /pipe|separated|list/}

exiftool "-Subject<${Subject@;$_=undef if not /^(pipe|separated|list)$/}" -sep "--" /path/to/files/

You would put your list of keywords, separated by the pipe character | between the parentheses.  This is a RegEx (Regular Expression) match if you are familiar with them.

Example output.  Notice that "Pipe" was removed as this is a case sensitive operation.  To make it case insensitive, you would add an i after $/.  The addition of ^( and )$ was to make sure that substrings were not matched, as in the example case of "pipe dream".  Remove them if you want to match substrings.
C:\>exiftool -g1 -a -s -Subject y:\!temp\Test4.jpg
---- XMP-dc ----
Subject                         : Pipe, pipe, pipe dream, separated

C:\>exiftool -P -overwrite_original "-Subject<${Subject@;$_=undef if not /^(pipe|separated|list)$/}" -sep "--" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -Subject y:\!temp\Test4.jpg
---- XMP-dc ----
Subject                         : pipe, separated
* 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).