Problem bulk renaming keywords

Started by magarlick, June 15, 2022, 07:43:19 AM

Previous topic - Next topic

magarlick

Hello.

I'm using exiftool 12.42 on Linux Mint, and I am trying to rename tags in an entire folder of subfolders and jpeg images.

I am following instructions on this post in this forum: https://exiftool.org/forum/index.php?topic=8265.0

To test, I am running the command on a single image. Here is the result of exiftool -G1 -s -keywords -subject *

[IPTC]          Keywords                        : art, artwork, illustration, dinosaur, compsognathus, hunter, prey, dragonfly, insect, theropod, Late jurassic, Europe, hunting, c. longipes, small
[XMP-dc]        Subject                         : art, artwork, illustration, dinosaur, compsognathus, hunter, prey, dragonfly, insect, theropod, Late jurassic, Europe, hunting, c. longipes, small


I want to change "jurassic" (part of the keyword "Late jurassic") to "Jurassic", so the whole keyword becomes "Late Jurassic". Here is the command I used: exiftool -api 'Filter=s/^jurassic$/Jurassic/;s/' -tagsfromfile @ -keywords -subject *

This output reads "1 file updated" and creates a copy of the original (which I don't want). Yet the keyword remains unchanged in both files. What am I doing wrong?

Some clarification. Once it's working, I want to rename (or delete) a whole bunch of keywords in a folder and OVERWRITE the original files (I'll make a backup first). The folder contains subfolders, which in turn contain the JPEGs.

Many thanks for any insight!

M.







StarGeek

Quote from: magarlick on June 15, 2022, 07:43:19 AM
I want to change "jurassic" (part of the keyword "Late jurassic") to "Jurassic", so the whole keyword becomes "Late Jurassic". Here is the command I used: exiftool -api 'Filter=s/^jurassic$/Jurassic/;s/' -tagsfromfile @ -keywords -subject *

The problem here is that you included the caret ^ and the dollar sign $.  In RegEx, these have special meanings.  The caret is an anchor for the start of the string, while the dollar sign anchors the end of the string (see this tutorial).  Your command will match only "jurassic" by itself, not as part of the keyword "Late jurassic".  So the filter call you want would be
-api 'Filter=s/jurassic/Jurassic/'

Your example command had a trailing ;s/ on the filter, which you don't want, as it might cause an error.  The semicolon marks the end of a command in Perl, so that is where you would end when you copy/paste.

QuoteThis output reads "1 file updated" and creates a copy of the original (which I don't want).

Add the -overwrite_original option to suppress the creation of backup files.

QuoteYet the keyword remains unchanged in both files.

One thing this command is going to do is copy the keywords back into the file even if they haven't changed, which is why you get the "updated" message.  If you're going to run this on a lot of files, then an -if option needs to be added to skip files where the keywords have not been changed.  This is a longer and more complex command
exiftool -if '$Keywords# ne $Keywords or $Subject# ne $Subject' -api 'Filter=s/jurassic/Jurassic/' -tagsfromfile @ -keywords -subject .

You'll want to use a dot to represent the current directory, especially if you want to recurse (add the -r (-recurse) option) into subdirectories.  Using an asterisk will prevent recursion and may cause unexpected effects on Linux (See Common Mistake #2, specifically #2e).
* 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).

magarlick

#2
Thank you so much for your reply - very appreciated.

So if I have understood properly, this is what I need:

exiftool -r -overwrite_original -if '$Keywords# ne $Keywords or $Subject# ne $Subject' -api 'Filter=s/jurassic/Jurassic/' -tagsfromfile @ -keywords -subject .

But that went through the list and said no files met the condition.

How do I modify the api to include multiple changes? If I want to change jurassic to Jurassic and triassic to Triassic, for example.

Phil Harvey

Stargeek's very smart command worked for me:

> exiftool a.jpg -keywords=jurassic
    1 image files updated
> exiftool -r -overwrite_original -if '$Keywords# ne $Keywords or $Subject# ne $Subject' -api 'Filter=s/jurassic/Jurassic/' -tagsfromfile @ -keywords -subject a.jpg
    1 image files updated
> exiftool -r -overwrite_original -if '$Keywords# ne $Keywords or $Subject# ne $Subject' -api 'Filter=s/jurassic/Jurassic/' -tagsfromfile @ -keywords -subject a.jpg
    1 files failed condition
> exiftool a.jpg -keywords
Keywords                        : Jurassic


To also change "triassic", you can do this:

'Filter=s/jurassic/Jurassic/;s/triassic/Triassic/'

- Phil 
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

magarlick

Yes it does work with single files but not with the files in the directory tree.

Phil Harvey

There is no difference running the command on one or more files or directories.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

magarlick

Ok, thanks, Phil. I put * at the end instead of . and it recursed through the folders. And thanks for the help re multiple naming.

Guys, you've been a great help. Exiftool is an amazing bit of code.

M.

StarGeek

Quote from: magarlick on June 15, 2022, 03:50:22 PM
Ok, thanks, Phil. I put * at the end instead of . and it recursed through the folders. And thanks for the help re multiple naming.

That was part of the Common Mistake #2 I linked.  If you want exiftool to recurse, you should use the -r (-recurse) option as I said above.
* 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).

magarlick

Just one more, if I may. How about replacing words in the Description metadata. I tried this:

exiftool -r -overwrite_original -if '$Description# ne Description' -api 'Filter=s/–/-/' -tagsfromfile @ -Description -subject *

(Trying to replace n-dashes with hyphens). It ran and said files were changed but they were not.

Phil Harvey

You forgot a "$" on the 2nd Description tag in your -if condition.  Adding the -v option will show problems like this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Also, are you checking if it has changed using exiftool or are you looking at the data in some other program?  For example, LightRoom will say "Description", but that's not specifically the Description tag.  There are three tags that LR will read.

Use the command in FAQ #3 to see all tags and their locations and verify changes from that.
* 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).

magarlick

Thanks again, Phil.

So the command you gave tells me that the 'description' is in tags Description, ImageDescription and Caption-Abstract. So I tried this command:

exiftool -r -v -overwrite_original -if '$Caption-Abstract# ne Caption-Abstract# or $Description# ne Description# or $ImageDescription# ne ImageDescription#' -api 'Filter=s/Chicxulub/chicxulub/' -tagsfromfile @ -Description -ImageDescription -Caption-Abstract *

I got

Condition: Bareword "Caption" not allowed while "strict subs" in use - Chicxulub Crater.jpg
-------- Chicxulub Crater.jpg (failed condition)
    1 files failed condition



StarGeek

You're still making the error that Phil pointed out, except now you've done it 3 times.
* 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).

magarlick

Yes, the dollar sign. Fixed and now works. Thanks.