setting Iptc:Caption-Abstract to some text that contains part of the filename

Started by msdobrescu, March 19, 2013, 03:00:23 PM

Previous topic - Next topic

msdobrescu

Hello,

I need to set Iptc:Caption-Abstract to some text that contains part of the filename.
Assuming the file is called "some file 'a' left.jpg", let's say I need to set Iptc:Caption-Abstract to "the left image of 'a'".
How could I achieve this?

Thank you.

Phil Harvey

Something like this should do what you want:

exiftool "-iptc:caption-abstract<the left image of ${filename;s/ left.*//}" FILE

where FILE is one or more file and/or directory names.  The substitution expression (s///) deletes everything from " left" onwards in the file name.

The quoting above should work in Windows.  Use single quotes instead if you are on Mac or Linux.

- 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 ($).

msdobrescu

Thank you for the fast reply. Assuming I need to scramble a little more the name, is there a way to specify something like "%15f", i.e to take 15 characters from the beginning, 3 from the middle, the last 5 ones, what should I do?
Where could I find the specs for expressions like the one you've proposed?
Are there any regular expressions available?

Thanks.

Phil Harvey

Beware: Regular expressions aren't for the faint of heart.  This is considered an advanced feature of ExifTool.

Google for "Perl regular expression" for documentation on this.  (Or even just "regular expression", since other languages use the same syntax.)

To do take 15 characters from the start and 5 from the end you could do this:

   ${filename;s/^(.{15}).*(.{5})\..*?$/some $1 text $2/}

where $1 and $2 would be the first 15 characters and the last 5.  To take ones from the middle I would need to have some way to tell which 3 characters.  The bit after (.{5}) in the expression just matches the file extension.  Note that this expression contains a backslash, which can be tricky to escape in some shells.

- 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 ($).

msdobrescu

Thanks,

Regular expressions are not a problem to me, I have used them in TextPad, Notepad++, Visual C, C# and many more. But Perl is totally alien to me.
I think that's the issue. Now, I have a basic sample to start with.

Thank you.

msdobrescu

Hello,

I have the following situation:

The text: blah blah lower blah blah g (optional here) left-01.jpg
The regex: /blah blah (lower|upper) blah blah (.{1}) (?:(.*))(left|right).*/

Here: http://www.solmetra.com/scripts/regex/index.php I can test and it shows:

Array
(
   
  • => blah blah lower blah blah g (optional here) left-01.jpg
        [1] => lower
        [2] => g
        [3] => optional here
        [4] => left
    )

    It seems to match as I expect, but exiftool seems not.
    What's wrong?

    Thanks.

Phil Harvey

This isn't what you expected?:

> exiftool a.jpg -comment='blah blah lower blah blah g (optional here) left-01.jpg'
    1 image files updated
> exiftool a.jpg -p '${comment;s/blah blah (lower|upper) blah blah (.{1}) (?:(.*))(left|right).*/$1|$2|$3|$4/}'
lower|g|(optional here) |left


- 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 ($).

msdobrescu

Yes, and I've just found the issue, it was a double quote missing that made the whole command a mess.

Thanks, I have to learn more now.  :)

muesli

Hello!

I have a similar problem as mentioned in this topic, maybe someone can help me:
I got about 500 photos of my childhood scanned by my parents. All the description is in the file names. They all have a three digit number followed by two times space, then the description, e.g. "025  Minimundus Klagenfurt.jpg". What do I have to do to get Minimundus Klagenfurt to the caption?
Thank you very much and best regards from Germany,

Müsli

StarGeek

Try
exiftool "-Caption-Abstract<${filename;s/^\d{3}  //}" FileOrDir

Try it out on a test file first to make sure it works like you want.
* 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).

muesli

Hello StarGeek,

thank you very much for your reply.
Unfortunately the result was "025  Minimundus Klagenfurt.jpg;s/^\d{3}  //}"
Did I make a mistake?
Thanks again an best wishes,

Müsli

Hayo Baan

Hayo Baan – Photography
Web: www.hayobaan.nl


StarGeek

Somehow you missed the opening brace.  The command works correctly here.

Notice I was able to replicate your output in the second command where I didn't have the opening brace.

c:\>exiftool "-Caption-Abstract<${filename;s/^\d{3}  //}" "X:\!temp\025  Minimundus Klagenfurt.jpg"
    1 image files updated

c:\>exiftool -caption-abstract "X:\!temp\025  Minimundus Klagenfurt.jpg"
Caption-Abstract                : Minimundus Klagenfurt.jpg

c:\>exiftool "-Caption-Abstract<$filename;s/^\d{3}  //}" "X:\!temp\025  Minimundus Klagenfurt.jpg"
    1 image files updated

c:\>exiftool -caption-abstract "X:\!temp\025  Minimundus Klagenfurt.jpg"
Caption-Abstract                : 025  Minimundus Klagenfurt.jpg;s/^\d{3}  //}

* 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).

muesli

Thank you StarGeek for your patience!
I did not forget the brace, I used copy and paste as well from your original post as from the new one. Your version with the missing brace produces the same output you had in this case and I have in both cases :(
I tried it with two opening braces but that screwed up things even more ;) I also tried to type the command by myself and not use copy and paste, same result.
Did you also use the windows command line?

Thanks, Müsli