ExifTool Forum

ExifTool => Newbies => Topic started by: dhw1977 on March 04, 2017, 12:20:45 PM

Title: How to remove characters from caption metadata
Post by: dhw1977 on March 04, 2017, 12:20:45 PM
I have successfully used the following command to copy the file names into the caption-abstract field:-

exiftool "-iptc:caption-abstract<filename" -r DIR

The filenames (and now captions) are of the form:-

F001 - Phototitle.jpg

Is there a command I can used to batch remove the 7 characters at the start and the 4 at the end, such that the caption that remains is:-

Phototitle

without the numbers or .jpg suffix?

Thank you
Title: Re: How to remove characters from caption metadata
Post by: StarGeek on March 04, 2017, 01:14:48 PM
Try this
exiftool "-Caption-abstract<${Caption-abstract;s/^.{7}(.*)\.[^.]+$/$1/}" -r DIR

^.{7} matches the first seven characters
\.[^.]+$ matches characters from the last dot to the end of string, i.e. the extension of the filename.  This is more flexible than just the last four characters and will work even if the filename ends in .jpeg or .tiff
(.*) captures everything else and copies it back into Caption-Abstract.
Title: Re: How to remove characters from caption metadata
Post by: dhw1977 on March 04, 2017, 02:32:36 PM
Thank you!  That has worked perfectly!

David
Title: Re: How to remove characters from caption metadata
Post by: Phil Harvey on March 05, 2017, 09:16:01 PM
Just as an alternative, this may be easier to understand:

exiftool "-Caption-abstract<${Caption-abstract;$_=substr($_,7,-4)}" -r DIR

- Phil
Title: Re: How to remove characters from caption metadata
Post by: dhw1977 on March 13, 2017, 07:22:27 PM
Thank you - yes that makes it easier for me to understand how to vary the number of characters removed.