selective removal of keywords?

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

Previous topic - Next topic

stonecherub

I have a need to remove selected keywords from image exif data. Some of mine I no longer use and on images borrowed from others for my website.

Is there some easy way? ..hard way?

Phil Harvey

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

stonecherub

Thanks for the tip. I presume the entire keyword needs to be entered in the command line. Mine are dotted as in "pinacate.volcano.lava flow.biggest" Would just "-keywords-=pinacate" work?

I am re-introduced to the utility of batch files.

Phil Harvey

The keyword needs to be an exact match.

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

stonecherub

I tried with one keyword and was informed that exiftool looked at 92 files but declined to change any of them. Where is this documented? I can try to figure it out myself and quit bugging you.

Phil Harvey

This is documented in the application documentation (which you see when you run exiftool with no arguments).  Look at the section under -TAG[+-]=[VALUE].  Also, see FAQ number 17.

If it didn't change any files, then there were no keywords that matched the ones you tried to remove.  Also see FAQ number 3 if you are still having no luck with 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 ($).

stonecherub

This makes no sense to me. I am using Friedemann Schmidt's Geosetter as a GUI. I brought up the edit data window for an image, copied the keyword from the keywords box and pasted it into my bat builder (Notepad++). Other images in the directory have the same keywords (added in a batch). The bat file looks like this:

ECHO OFF
CD /D H:\images\TecoRestored
exiftool -keywords-=Pinacate.Monogenetic.Fresh%20cones.Tecolote.Cone H:\images\TecoRestored
PAUSE

There is a space in one part (Fresh cones) so I put in %20 for the space character. Keywords are separated with semi-colons but leaving it or removing it makes no difference.

The result is:

1 directories scanned
0 image files updated
92 image files unchanged

I can't figure it out.

StarGeek

The problem I see is that you don't have keywords, you have a single keyword which encompasses all of "pinacate.volcano.lava flow.biggest".  Unless all the files in the directory have the exact same keyword, it wouldn't be easy to remove just "pinacate" as a single command.

If you want to convert the single grouped keyword into individual keywords, you can use the -sep option as mentioned in the FAQ that Phil pointed to.  In this case
exiftool -sep "." -tagsfromfile @ -keywords H:\images\TecoRestored
That will separate the keywords for you.  You can then use
exiftool -keywords-=pinacate H:\images\TecoRestored
to remove pinacate from the keywords.

If you want to remove a keyword with a space, such as "lava flow", you can put quotes around the word
exiftool -keywords-="lava flow" H:\images\TecoRestored

I would suggest making sure you have a backup of your images before trying full directory operations just in case you remove data that you want to keep.  Also, separating the keywords like that might not be readable in the original program that put in the keywords that way.
* 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).

stonecherub

It occurs to me that, in this case, I might be ahead by cleaning out all the keywords and starting from an empty object. Can I do that?

Phil Harvey

To remove all IPTC keywords, use -keywords= on the command line.  To remove XMP keywords, use -xmp:subject=.  I'm not sure where your keywords are stored.  You can remove both at the same time if you want.

- 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

QuoteThe keyword needs to be an exact match.
- Phil
Is this statement still valid ?
I would like to be able to filter the "Hierarchical Subject".
Quote---- XMP-lr ----
Hierarchical Subject            : gens|famille|famille Beatrice|Mike, places|Brasil|Minas Gerais|Itabira
in two different ways:
1. remove every keyword starting with "gens" (people).
2. remove the first level of the keyword everywhere else (in some tools this level is considered as category) because they have no interest as keyword. in the above example "places" should be removed and we would keep only "Brasil|Minas Gerais|Itabira".
What do you think ?
Thanks, Philippe






Phil Harvey

Hi Philippe,

Since this original post there is a new advanced formatting feature that allows you to do arbitrary filtering of tag values.  Try this:

exiftool "-HierarchicalSubject<${HierarchicalSubject;s/^gens\|[^,]+(, )?//;s/(^|, )[^\|]+\|/$1/}" FILE

- 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

 There is one thing to watch for, though. Programs like Lightroom will also write the base keywords to iptc keywords and XMP subject. So in the case of the gens keyword Mike, it would have to be removed separately from keywords and subject.
* 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

Also, I realized that I needed to add a -sep ", " to the command so the list items get separated back properly again.

- 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

Thank you very much Phil !
It works perfectly with the first example.
When I add some tags it doesn't make all the job.
Before:
Hierarchical Subject            : construction|bâtiment|fenêtre, gens|famille|famille Beatrice|Mike, places|Brasil|Minas Gerais|Ipoema, style|portrait
After:
Hierarchical Subject            : bâtiment|fenêtre, gens|famille|famille Beatrice|Mike, places|Brasil|Minas Gerais|Ipoema, style|portrait
Only Construction has gone.
Is there a place where I can find the syntax ? (My neurones will make some knots ...  :-[)

I've not understood the place / the need of -sep ", " ...

@StarGeek, yes, that will be the next topic. And remove all "people" related simple keywords may be a challenge...
Unless it was possible to recreate them from the Hierarchical Subject after cleaning ...  ;)