How to rename keywords (subjects) with ExifTool?

Started by marekl, April 30, 2017, 05:58:20 PM

Previous topic - Next topic

marekl

Is there a way how to rename keywords using ExifTool? For example: There is a keyword AA in some JPGs (I don't know what files) and I want to change it to A A. BB to B B and so on. I write about keywords, but it is subjects in XMP I think.

There will be about twenty keywords I want to rename this way. A batch with twenty similar commands could solve it then.

Thank you

StarGeek

I would suggest using the -API "Filter=" command.  It helps if you know something Regular Expressions, but for the basic stuff it can be pretty simple. 

Your command would be something like this:
exiftool -api "Filter=s/^AA$/A A/;s/^BB$/B B/;s/^CC$/C C/" -tagsfromfile @ -keywords -subject FileOrDir

There are some things to watch for.  Certain characters in RegEx have special meanings.  If you need to use any of these characters .^$*+?()[{\|, you need to put a backslash \ before them.  My example above assumes that you are looking for complete case sensitive keywords.  To make the replacement case insensitive, put an i after the 3rd slash after the s e.g. s/^AA$/A A/i;s/^BB$/B B/i;s/^CC$/C C/i.  If you not looking for full keywords, just replacing part, remove the caret and the dollar sign.  So if you have AAB and want A AB, you would use s/AA/A A/;s/BB/B B/;s/CC/C C/.  To replace all occurances, add a g i.e. to change AABAA to A ABA A, use s/AA/A A/g;s/BB/B B/g;s/CC/C C/g.  To be case insensitive and global, use both the i and g.

Example output:
C:\>exiftool -G1 -s -keywords -subject X:\!temp\Test3.jpg
[IPTC]          Keywords                        : ocean, HiThere
[XMP-dc]        Subject                         : XMP-dc:Subject, More, AAbbCCddAa

C:\>exiftool -api "Filter=s/Ocean/Beach/i;s/Hithere/Hi There/;s/aa/A A/gi" -tagsfromfile @ -keywords -subject X:\!temp\Test3.jpg
    1 image files updated

C:\>exiftool -G1 -s -keywords -subject X:\!temp\Test3.jpg
[IPTC]          Keywords                        : Beach, HiThere
[XMP-dc]        Subject                         : XMP-dc:Subject, More, A AbbCCddA A


Here I changed ocean to Beach with the case insensitive match.  I was not able to change HiThere to Hi There because I didn't add the i so the match had to be case sensitive.  Finally, all double As, lower or upper case, became A As due to the g (global) and i (case insensitive).

Hope this helps.
* 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).

marekl