selective removal of keywords?

Started by stonecherub, December 15, 2012, 07:08:17 PM

Previous topic - Next topic

Phil Harvey

Sorry for the delay in responding.

You can't use other tags by name in these expressions.  Instead, you would need to do something like this:

exiftool -p "${HierarchicalSubject;my $loc=$self->GetValue('Location');s/(places\|[^\|,]*\|[^\|,]*\|[^\|,]*)/$1\|$loc/}"

But I don't have time to try this out to see if it would work.  Also, it would get more complicated if there is more than one type of Location tag.

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

phweyland

#31
Hi Phil,
This works great straight ahead !!  :)
New things to learn ...
I've just to treat the case when Location is not present.

exiftool -p "${HierarchicalSubject;my $loc=$self->GetValue('Location');s/(places\|[^\|,]*\|[^\|,]*\|[^\|,]*)/$1\|$loc/}"  D:\Documents\Images\Photos\2010\2017\20171118_Tiradentes\20171119_Tiradentes_004.xmp
genre|graine, piwigo|2010s|2017|11-18 Tiradentes, places|Brasil|Minas Gerais|Tiradentes|Pousada Alma Serra

Thank you so much.

phweyland

Hi Phil,
Thanks to your guiding, the following line adds IPTC:Location to IPTC:HierarchicalSubject if IPTC:Location exists. Otherwise lets the file unchanged. Great !

exiftool -overwrite_original -tagsFromFile @ -m -if "$XMP-iptcCore:Location" "-HierarchicalSubject<${HierarchicalSubject;my $loc=$self->GetValue('Location');s/(places\|[^\|,]*\|[^\|,]*\|[^\|,]*)\|.*|$/$1\|$loc/}" -sep ", "  D:\Documents\Images\Photos\2010\2017\20171118_Tiradentes\*.xmp

Works also inside argument file.

However, if I add the command -P (command line or argument file) the substitution doesn't happen. Is there a reason for that ?
Thank you



Phil Harvey

Adding -P shouldn't affect things unless you put it in between another option and its argument.  What was the command you used?

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

phweyland

I put the command -P as the first command.
I've not tried in other position. If it behaves another way on other position I'll report it.
Philippe

Phil Harvey

Oh.  That's the problem.  You used -p, not -P.  It must be capitalized.

Or, wait.  What are you trying to do?  -P preserves the file modification date/time when writing.  -p specifies a print format string.

(The documentation explains all this.)

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

phweyland

Yes, I use -P (capitalized) to preserve the modification time.
For the other cases you helped me to solve, it was not an issue.

But in the first case below, file is not updated (location not written) while the second case works fine:

C:\Users\philippe>exiftool -P -overwrite_original -tagsFromFile @ -m -if "$XMP-iptcCore:Location" "-HierarchicalSubject<${HierarchicalSubject;my $loc=$self->GetValue('Location');s/(places\|[^\|,]*\|[^\|,]*\|[^\|,]*)\|.*|$/$1\|$loc/}" -sep ", "  D:\Documents\Images\Photos\2010\2017\20171118_Tiradentes\*.xmp
    1 files failed condition
    2 image files updated

C:\Users\philippe>exiftool -overwrite_original -tagsFromFile @ -m -if "$XMP-iptcCore:Location" "-HierarchicalSubject<${HierarchicalSubject;my $loc=$self->GetValue('Location');s/(places\|[^\|,]*\|[^\|,]*\|[^\|,]*)\|.*|$/$1\|$loc/}" -sep ", "  D:\Documents\Images\Photos\2010\2017\20171118_Tiradentes\*.xmp
    1 files failed condition
    2 image files updated

Phil Harvey

Could you add a -v2 to each command so I can see the differences?

Thanks.

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

phweyland

Hi Phil,
The 2 cases return the same data with -v2.

I've just understood my mistake.  :-[
I thought the file was not updated because Notepad++ did not prompt me for change with -P (of course because the modification date is preserved !)
If I reload from disk manually the file is correctly modified.
Sorry for inconvenience...

Thank you again.

Phil Harvey

Great.  Glad you figured it out

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

StarGeek

Quote from: phweyland on April 08, 2018, 09:14:54 AM
I thought the file was not updated because Notepad++ did not prompt me for change with -P (of course because the modification date is preserved !)

I've had that happen with Notepad++ on occasion.  I find that if I'm expecting a change and don't get the prompt, clicking something outside of Notepad++ so it isn't the active window, and then reselecting it will get it to prompt for reload.
* 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).

Phil Harvey

I'm guessing that won't work in this case since it seems as if Notepad is checking the file modification date/time to decide whether or not to reload.

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

StarGeek

Yep, it looks like.  I had assumed that it was using some feature of the NTFS that can notify a program when there's a change in the file.  I don't know too much about the details but I remember seeing some other program mention it.
* 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).

Neil

On MacOS.

I'm trying to do your example below with about 60 more specific keywords to remove, but keep the good ones.
The individual keyword removal example below works fine. I'd like to run exiftool once per file and remove all unwanted keywords. There are also duplicate keywords. The application used to write the IPTC data to the original jpg and tif files seemed to randomly add words from the Captions field to the Keywords field in the original. Many, not all. Trying to clean that up and leave the correct keywords.

I read the documentation   -TAG[+-]<=DATFILE                Write tag value from contents of file
Tried that with a list of the unwanted keywords in DATFILE, one per line.

exiftool '-keywords-<=keywords.txt' /Users/Neil/Desktop/CT02_58_60009\ copy.jpg

This only seems to work if there is only one keyword in keywords.txt, removing that one keyword.
Is the approach correct?
What if any is the format for multiple keywords in the contents of DATFILE (keywords.txt).
What is the correct approach?

exiftool -s /Users/Neil/Desktop/CT02_58_60009\ copy.jpg | grep Keywords

shows the following output:

Keywords                        : Grandma Hannie Hanson, Erling Warren, Hannie family, Erling, Erling

Advice would be appreciated. Thank you.

Quote from: Phil Harvey on December 15, 2012, 08:52:52 PM
To remove keywords "one" and "two" from all images in directory "DIR":

exiftool -keywords-=one -keywords-=two DIR

(that is assuming that they are stored in the IPTC keywords.  Read FAQ 2 and 3 to figure out the tag name you should actually use.)

- Phil

StarGeek

Quote from: Neil on June 13, 2022, 01:44:49 AM
I read the documentation   -TAG[+-]<=DATFILE                Write tag value from contents of file
Tried that with a list of the unwanted keywords in DATFILE, one per line.

exiftool '-keywords-<=keywords.txt' /Users/Neil/Desktop/CT02_58_60009\ copy.jpg

This only seems to work if there is only one keyword in keywords.txt, removing that one keyword.
Is the approach correct?

No.  Doing that would tell exiftool to look and remove a single tag with the entire contents of the file.  There is no parsing done on a DATFILE.  It is treated as a single value, as is.

What you want to do is create a ARGFILE and use the -@ (Argfile) option. Using your example keywords, it you wanted to remove "Erling Warren" and "Erling", your ARGFILE would be
-Keywords-=Erling Warren
-Keywords-=Erling


And then you would run the command
exiftool -@ keywords.txt /path/to/files/

Note that even though there's a space in "Erling Warren", you do not use quotes around it.  The quotes are needed on the command line, but not used in a ARGFILE. 
* 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).