ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: lclarke522 on June 01, 2015, 08:19:45 PM

Title: Finding a string within a tag
Post by: lclarke522 on June 01, 2015, 08:19:45 PM
Hi! I am trying to change the titles of a batch of images so that it reflects the camera maker, model, and lens. However, in some cases the camera maker is already a part of the value stored in the model tag and I don't want to display that twice. 

I'm having trouble with the syntax of "if $model begins with $make then..."

I doesn't have to be "begins with." I'd be satisfied with "contains."

Thanks in advance  :)
Title: Re: Finding a string within a tag
Post by: Hayo Baan on June 02, 2015, 03:03:38 AM
I think you are looking for the following regular expression for your -if: $model =~ /^$make/
This will match only when model starts with make. If you want to match case insensitive, add an i after the last /. To negate the match, use !~ instead of =~.

Hope this helps,
Hayo
Title: Re: Finding a string within a tag
Post by: Phil Harvey on June 02, 2015, 07:34:06 AM
Alternatively, maybe you could strip the Make from the Model when copying, something like this:

exiftool "-title<${Make} ${Model;s/\s*$$self{VALUE}{Make}\s*//i} ${LensID}" -m FILE

Here I am taking advantage of the undocumented ExifTool internals to access the Make tag from within the advanced formatting expression for Model.  But a disadvantage of doing it this way is that you will get a warning due to an uninitialized value in this expression if Make doesn't exist.

- Phil
Title: Re: Finding a string within a tag
Post by: lclarke522 on June 02, 2015, 09:52:02 AM
Thank you both - I tried Phil's and it was perfect for my needs.