ExifTool Forum

ExifTool => Newbies => Topic started by: Tribo0n on November 22, 2018, 11:52:03 AM

Title: Remove everything after fix value in the IPTC field caption
Post by: Tribo0n on November 22, 2018, 11:52:03 AM
Hello,
i'm new here and need help with exiftool.
I got thousands of photos in a folder and i would like to remove everything after some fix values (fix values included) in all that images in the iptc caption field 120.

Example before:
HOLLYWOOD - APRIL 30: Actors James Morrison (L) and Jeffrey Nordling attend Fox's "24" Series Finale Party held at Boulevard 3 on April 30, 2010 in Hollywood, California. (Photo by XXX/YYY) /-DDD-
HOLLYWOOD - APRIL 30: Actors James Morrison (L) and Jeffrey Nordling attend Fox's "24" Series Finale Party held at Boulevard 3 on April 30, 2010 in Hollywood, California. Photo:
HOLLYWOOD - APRIL 30: Actors James Morrison (L) and Jeffrey Nordling attend Fox's "24" Series Finale Party held at Boulevard 3 on April 30, 2010 in Hollywood, California.
Credit: XXX/YYY

HOLLYWOOD - APRIL 30: Actors James Morrison (L) and Jeffrey Nordling attend Fox's "24" Series Finale Party held at Boulevard 3 on April 30, 2010 in Hollywood, California.
Photo: XXX/CCC

Example after:
HOLLYWOOD - APRIL 30: Actors James Morrison (L) and Jeffrey Nordling attend Fox's "24" Series Finale Party held at Boulevard 3 on April 30, 2010 in Hollywood, California.

Can i use a batch script to start the action?

i Just found that, but my english is not so good to understand all of that, how to use it
exiftool "-iptc:caption-abstract

Thanks a lot

André
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: StarGeek on November 22, 2018, 04:52:52 PM
On example #2, does it just end with "Photo:" or is there supposed to be something after it?

The basic command would be something like this:
exiftool "-Caption-Abstract<${Caption-Abstract;s/\(Photo by.*?$//;s/Photo:$//;s/^Credit:.*//m;s/^Photo:.*$//m;}" FileOrDir

But you would have to be very careful with this.  If any of these patterns just happened to occur earlier in the string then it would be truncated at that point.

This command would only work on the IPTC:Caption-Abstract tag in the files.  You might also check to see if XMP:Description also contained data. 

This command creates backup files.  Add -overwrite_original to suppress the creation of backup files.  Add -r to recurse into subdirectories.  If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Tribo0n on November 23, 2018, 03:08:26 AM
Hi StarGeek,
thanks for your answere. I will try it
After each example there are more then just "Photo or Credit"
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: StarGeek on November 23, 2018, 03:50:49 AM
Quote from: Tribo0n on November 23, 2018, 03:08:26 AM
After each example there are more then just "Photo or Credit"

In that case, in the above command, change s/Photo:$//; to s/Photo:.*?$//;
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Tribo0n on November 23, 2018, 08:16:17 AM
Thanks a lot, it works now
@echo off
exiftool "-Caption-Abstract<${Caption-Abstract;s/\(Photo by.*?$//;s/Photo:.*?$//;s/^Credit:.*//m;s/^Photo:.*$//m;}" D:\Test\ -overwrite_original
pause


The script didn't remove the the next paragraph. What need to be change that everything after Photo by will be removed?

How can i remove   (testtest/   and all following content? If i edit the script it gives an error. I think its cause of ( and /


André
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: StarGeek on November 23, 2018, 12:23:48 PM
You're correct, you have to escape the ( and / by putting a backslash in front of them.  So, s/\(testtest\/.*//;

All of these characters [/\^$.|?*+() need to be escaped as they have special meanings in regex (Regular Expressions).

You can use RegEx101 (https://regex101.com/) to test things.  Each s/ / / is a single regex expression, where what matches between the first two slashes is replaced by what's between 2nd and 3rd slash.  There are certain options you can place after the 3rd slash as modifiers. 

Regex is a very complex subject and there are lots of websites out there that go into more depth on the subject.
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Tribo0n on December 07, 2018, 12:59:33 AM
Quote from: Tribo0n on November 23, 2018, 08:16:17 AM
The script didn't remove the the next paragraph. What need to be change that everything after Photo by will be removed?
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Phil Harvey on December 07, 2018, 06:29:54 AM
Add ;s/Photo.*//

- Phil
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Tribo0n on December 12, 2018, 04:45:54 PM
It don't remove the next paragraph
Thats my code:
@echo off
exiftool "-Caption-Abstract<${Caption-Abstract;s/Credit:.*//;s/Credit by.*//;s/Photo:.*//;s/Photo by.*//;s/\(Photo by.*?$//;s/Photo:.*?$//;s/^Credit:.*//m;s/^Photo:.*$//m;}" "-artist=XXX" "-CopyrightNotice=XXX" "-Credit=XXX" "-Source=XXX" "-Writer-Editor=XXX" "-Contact=XXX" "-By-line=XXX" "-By-lineTitle=XXX" "-OriginalTransmissionReference=XXX" "-SpecialInstructions=" "-SupplementalCategories=" "-LocalCaption=" F:\test\ -overwrite_original -r
pause


Example
Bla Bla Bla at Hamburg, Germany
Photo by XXX/YYY
Ref: 356
Hamburg


Everything after Photo by should be removed. Whats wrong?
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: StarGeek on December 12, 2018, 07:05:30 PM
Try s/Photo.*//s

You might also try changing any trailing m's in the previous commands to s.  I was trying to be careful with what was deleted in my original post.  The trailing m treats each line separately (multi-line).  The s treats the whole thing as a single line.
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Tribo0n on July 19, 2019, 04:54:53 AM
Is it possible to modify this command by having a text file with all values from which the caption should be cutted off?

This is my code:
@echo off
exiftool "-Caption-Abstract<${Caption-Abstract;s/Credit:.*//s;s/credit:.*//s;s/Credit by.*//s;s/credit by.*//s;s/Photo:.*//s;s/photo:.*//s;s/Photo by.*//s;;s/photo by.*//s;;s/Photo By.*//s}" F:\images -overwrite_original -r
pause
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Phil Harvey on July 19, 2019, 07:01:17 AM
The .bat file is a text file.  And it contains all of the values to be cut off.

If your question is about a different format text file, the answer is "no".

- Phil
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Tribo0n on July 20, 2019, 10:37:35 AM
Yeah, i mean a diffrent formated text file
For example this.

credit:
Credit:
credit by:
Photo:
photo:
Photo by:
photo by:
Photo by
Title: Re: Remove everything after fix value in the IPTC field caption
Post by: Phil Harvey on July 22, 2019, 07:55:42 AM
I can't think of a way to do this.

- Phil