ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: amyz on September 09, 2014, 08:38:00 PM

Title: Can I extract specific information from a comment and write it to the file?
Post by: amyz on September 09, 2014, 08:38:00 PM
I want to extract the date/time information from a large amount of photos.  However, these files only seem to have a "Modify Date," not a creation date.  I found that the date information was hidden inside a long "Comment." 

An example of the information in the Comment looks like this:  Trg: M 3/15.Dat: 2009-08-29 15:14:11.MP:  3.Tmp: 102 F.Bat: 14466.Lht: 985.Ill: Off.Exp: 0006,2.Ctr: 192.Brt: 64.Shp: 128.PIR: 100.Lbl: JRBP South 082509.Nam: M0010103.JPG.SN:  PM0701179.Ver: 2.0.7.20060629.Rst: 1.Cfg: 0003004664050A01000F03E80000FFFFFFFFFFFFFFFFFFFFFFFF00000005FFFFFFFFFFFFFFFFFFFFFFFFC040005E8080524A50425320756F68743020323830350039000099026A803B19.

I would like to know if I can take the date information (or any of the other categories), in this case, "2009-08-29 15:14:11" out of each photo's "Comment" section and write it to all my files. 
Title: Re: Can I extract specific information from a comment and write it to the file?
Post by: Phil Harvey on September 10, 2014, 07:07:19 AM
Yes.  If the date/time is always in this format, you can do something like this:

exiftool "-createdate<${comment;s/.*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*/$1/s}" -if "not $createdate" DIR

where DIR is the name of a directory containing the images.  (The quoting above is for Windows.  Use single quotes instead of double quotes if you are on Mac or Linux.)

Here I have used an advanced formatting expression to isolate the date/time in the comment before copying it to CreateDate.  And I have used a -if condition to avoid writing to files which already contain a CreateDate tag.

- Phil
Title: Re: Can I extract specific information from a comment and write it to the file?
Post by: amyz on September 12, 2014, 05:32:33 AM
Thank you for your quick response.  The date/time is indeed always in this exact format, but when I tried to use it (only modification is that I put single quotes on my Mac), it gave me an error:

-bash: syntax error near unexpected token `)'

I'm new to Exiftool and don't exactly understand what you wrote enough to find the syntax error myself.  Do you have any thoughts?
Title: Re: Can I extract specific information from a comment and write it to the file?
Post by: Phil Harvey on September 12, 2014, 07:20:52 AM
Quote from: Phil Harvey on September 10, 2014, 07:07:19 AM
(The quoting above is for Windows.  Use single quotes instead of double quotes if you are on Mac or Linux.)
Title: Re: Can I extract specific information from a comment and write it to the file?
Post by: StarGeek on September 12, 2014, 04:55:19 PM
Just a guess based upon your error output, but maybe you have a ` in your command?  You have to use regular quotes ', not smart quotes or backticks.
Title: Re: Can I extract specific information from a comment and write it to the file?
Post by: Phil Harvey on September 12, 2014, 07:06:15 PM
I didn't read your post carefully enough.  I see now you said you used single quotes.

I just tried this on my Mac under bash, and it worked fine.  I can get the error you found in bash if I have an unmatched quote in a command.  So my guess is that StarGeek is right, and one of your single quotes was a backtick.

- Phil
Title: Re: Can I extract specific information from a comment and write it to the file?
Post by: amyz on September 13, 2014, 12:00:30 AM
I tried typing it in again, and for whatever reason, it worked this time around! Thanks for your help.