ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Tom Cunningham on August 08, 2016, 11:21:52 PM

Title: Arbitrary string replacement
Post by: Tom Cunningham on August 08, 2016, 11:21:52 PM
Is there any way to perform a substitution on a string no matter what tag it is associated with?  In other words, if the string "Ettie" appears in multiple places in the metadata, is there any way to change it to "Effie" in all of those locations without having to specify a tag?  What if the length of the string changes?
Title: Re: Arbitrary string replacement
Post by: Hayo Baan on August 09, 2016, 02:02:54 AM
This is not possible with a simple command. To do this you would need to list all tags, filter the ones with the string in them and then replace their values. Doable, but not without some additional scripting.
Title: Re: Arbitrary string replacement
Post by: Phil Harvey on August 09, 2016, 08:04:19 AM
The API Filter option (https://exiftool.org/ExifTool.html#Filter) allows you to apply an arbitrary filter to the value of all extracted tags:

exiftool -api "Filter=s/Ettie/Effie/g" DIR

So you should be able to do something like this to write these changes back to the file:

exiftool -api "Filter=s/Ettie/Effie/g" -tagsfromfile @ -all:all DIR

This will completely rewrite the metadata of each file, so changing the length of the string isn't a problem.

@Hayo: ExifTool does so much that I have trouble keeping track of it all too! :)

- Phil

Title: Re: Arbitrary string replacement
Post by: Hayo Baan on August 09, 2016, 11:33:50 AM
Quote from: Phil Harvey on August 09, 2016, 08:04:19 AM
@Hayo: ExifTool does so much that I have trouble keeping track of it all too! :)

Awesome, I stand corrected, this really is a sweet option to use 8)
Title: Re: Arbitrary string replacement
Post by: Tom Cunningham on August 09, 2016, 12:38:06 PM
Once again, thanks so much for your help, guys!
Title: Re: Arbitrary string replacement
Post by: StarGeek on August 18, 2016, 11:20:49 PM
Quote from: Hayo Baan on August 09, 2016, 11:33:50 AM
Awesome, I stand corrected, this really is a sweet option to use 8)

I remember when he introduced this, making a mental note to look into it further, and promptly forgetting about it.

Looking into this, I see I can combine a several old user defined tags, several commands from my bat files, and one annoyingly long script into a single command.  Very cool. 
Title: Re: Arbitrary string replacement
Post by: Phil Harvey on August 19, 2016, 07:50:38 AM
Quote from: StarGeek on August 18, 2016, 11:20:49 PM
Looking into this, I see I can combine a several old user defined tags, several commands from my bat files, and one annoyingly long script into a single command.  Very cool.

Excellent. :)