ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Elazul on January 31, 2020, 06:20:32 AM

Title: Replace keyword with new value or add if not present
Post by: Elazul on January 31, 2020, 06:20:32 AM
I have a keywords list that looks similar to this:
Keywords                        : Merlin ID:139777188, 20190227, REMOTE, "Merlin Crop: 0 0 2489 1376"
I need to add a new "Merlin Crop: ? ? ? ?" keyword instead of existing one(if present). The hard part is to do this in one exiftool command run, as in our architecture for every exiftool call a microservice is invoked through HTTP with image attached, meaning we could save a lot of time if we do it in one call instead of two.

What I tried so far:
exiftool '-keywords<${keywords@;$_="Merlin Crop 1 2 3 4" if /.?Merlin Crop.*/}' image.jpg - works only if there's a Merlin Crop keyword already in the list.
exiftool '-keywords<${keywords@;$_=undef if /.?Merlin Crop.*/}' -keywords+='"Merlin Crop 1 2 3 4"' image.jpg - looks like only -keywords+= gets executed and old Merlin Crop is still in the list.

Could someone please help me figure out the proper way to combine these two?
Title: Re: Replace keyword with new value or add if not present
Post by: Phil Harvey on January 31, 2020, 07:22:12 AM
You were very close, but the += is not necessary since you were already copying the other keywords.  Also, you need the -sep option to break the keywords apart again after they are interpolated in the string.  Try this:

exiftool '-keywords<${keywords@;$_=undef if /.?Merlin Crop.*/}' -keywords='"Merlin Crop 1 2 3 4"' -sep // image.jpg

- Phil
Title: Re: Replace keyword with new value or add if not present
Post by: Elazul on January 31, 2020, 07:58:13 AM
Perfect! Works like a charm. :)

Thanks for your help, Phil, much appreciated.

PS: exiftool is pretty cool :)
Title: Re: Replace keyword with new value or add if not present
Post by: Phil Harvey on January 31, 2020, 08:16:05 AM
Quote from: Elazul on January 31, 2020, 07:58:13 AM
PS: exiftool is pretty cool :)

You must be a true geek. ;)