How to remove characters from caption metadata

Started by dhw1977, March 04, 2017, 12:20:45 PM

Previous topic - Next topic

dhw1977

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

StarGeek

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

dhw1977


Phil Harvey

Just as an alternative, this may be easier to understand:

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

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

dhw1977

Thank you - yes that makes it easier for me to understand how to vary the number of characters removed.