Arbitrary string replacement

Started by Tom Cunningham, August 08, 2016, 11:21:52 PM

Previous topic - Next topic

Tom Cunningham

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?

Hayo Baan

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.
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

The API Filter option 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

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

Hayo Baan

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)
Hayo Baan – Photography
Web: www.hayobaan.nl

Tom Cunningham

Once again, thanks so much for your help, guys!

StarGeek

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. 
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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. :)
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).