[solved] How to split up "multi word tags"?

Started by Koala, October 28, 2016, 04:53:29 PM

Previous topic - Next topic

Koala

Hello exiftool forum,

I am about to adding tags to my collection of ~18.000 pictures. For this I wrote a shell/bash script which converted folder names to IPTC:Keywords using exiftool.

After this, my images from .../vehicle/motorbike/friend+me/my_workshop/..... .jpg contain those tags:
Keywords       : vehicle, motorbike, friend+me, my_workshop

To get a better structure of tags I would like to split up "multi word tags" so the result should be this:
Keywords       : vehicle, motorbike, friend, me, my, workshop

Is there a chance to perform this with a single(?) exiftool command line maybe using -sep option with a group of characters [+, _, ...]?
Or is necessary to manipulate the keywords with separate shell/bash script commands?(read out keywords -> manipulate string -> write back)

Thank you for your hints and best regards

Koala

StarGeek

Try
exiftool -sep ", " "-keywords<${keywords;s/[+_]/, /g}" FileOrDir

Put all the characters you want to use as separators between the brackets.  This will replace any character between the brackets with a CommaSpace, which is the Sep sequence. 

Don't put a comma between the brackets unless you change the Sep value in both places, after the -Sep option and between the second and third slashes /, /.  If you don't change them, you'll end up with a lot of blank keywords.
* 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).

Koala

Thanks for your quick reply.

Unfortionally it returns this error message
$ exiftool -sep ", " "-keywords<${keywords;s/[+_]/, /g}" motorrad.jpg
bash: -keywords<${keywords;s/[+_]/, /g}: Falsche Variablenersetzung (wrong variable substitution).


$ exiftool -ver
10.16

Ubuntu 12.04

StarGeek

My apologies, I didn't catch that you mentioned bash.

Change the double quotes in the command into single quotes for linux/mac systems.
* 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).

Koala

Solved!
$ exiftool -sep ', ' '-keywords<${keywords;s/[+_]/, /g}' motorrad.jpg
    1 image files updated

Keywords changed as expected.

Thank you very much  :)

Koala

Koala

additional ", " [CommaSpace] will be generated as I have to handle
- blank space and
- characters at the end/beginning of words:

I start with this keywords:
Keywords                        : technics, dot., work-shop, blank space, _under

I manipulate successfully:
$ exiftool -sep ', ' '-keywords<${keywords;s/[-_. ]/, /g}' motorrad.jpg
    1 image files updated


I receive this:
Keywords                        : technics, , dot, , , work, shop, , blank, space, , , under
The keywords are all as I expected, but can I avoid multiple CommaSpace there? Or can I remove them afterwards?

StarGeek

That gets more complicated. 

I should have said don't put a comma or a space unless you change the -sep option. 

Do you want to keep the leading/trailing characters?  For example,  should dot. end up as dot  Or do you only want to split when the target characters are in the middle of the keyword, e.g. middle.dot should be split, but enddot. should stay enddot.?


If you're fine with losing leading/trailing characters, try this:
exiftool -sep ', ' '-keywords<${keywords;s/[-_. ]/, /g;s/(, )+/, /g}' motorrad.jpg


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

Koala

Thanks again for your support.

Yes, I would like to handle all leading/middle/trailing special characters.

It seems, as handling of blank space makes it more difficult, because this adds an additional CommaSpace after each separator (existing CommaSpace)
I start with this:
Keywords                        : technics, dot., work-shop, blank space, _under
I execute your modified command:
exiftool -sep ', ' '-keywords<${keywords;s/[-_. ]/, /g;s/(, )+/, /g}' motorrad.jpg
-> Keywords                        : technics, , dot, , , work, shop, , blank, space, , under





After a few trials and errors I found this work around (split it in 2 steps):
I start with this:
Keywords                        : technics, dot., work-shop, blank space, _under

Step 1: I replace all special characters by CommaSpace (leading/middle/trailing):
exiftool -sep ', ' '-keywords<${keywords;s/[-_. ]/, /g}' motorrad.jpg
-> Keywords                        : technics, , dot, , , work, shop, , blank, space, , , under


Step 2: I execute a modified version of the 2nd part of you command (removing SpaceCommas(!))
exiftool -sep ', ' '-keywords<${keywords;s/( ,)+//g}' motorrad.jpg
-> Keywords                        : technics, dot, work, shop, blank, space, under
  :)

Strangely, it does not work, If I just combine step 1 and 2 into one command like this:
exiftool -sep ', ' '-keywords<${keywords;s/[-_. ]/, /g;s/( ,)+//g}' motorrad.jpg
-> Keywords                        : technics, , dot, , work, shop, , blank, space, , under


Maybe you can streamline this into one command? Otherwise I perform 2 runs through my collection - its ok.

Best regards

Koala

StarGeek

Sorry, my mistake.  I was rushing and didn't test it properly.  I know better than to try and answer things without testing.

Change the -sep and then it should work.  Try this:
exiftool -sep '##' '-keywords<${keywords;s/[-_. ]/##/g;s/(##)+/##/g}' motorrad.jpg

As long as Hashtags aren't part of the characters you're splitting on, I think that would do it.  It worked here with your test data.

c:\>exiftool -keywords X:\!temp\Test.jpg
Keywords                        : technics, dot., work-shop, blank space, _under

c:\>exiftool -P -overwrite_original -sep "##" "-keywords<${keywords;s/[-_. ]/##/g;s/(##)+/##/g}" X:\!temp\Test.jpg
    1 image files updated

c:\>exiftool -keywords X:\!temp\Test.jpg
Keywords                        : technics, dot, work, shop, blank, space, under
* 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).

Koala

Perfect!
For Linux I just replaced double quotes by single quotes
exiftool -P -overwrite_original -sep '##' '-keywords<${keywords;s/[-_. ]/##/g;s/(##)+/##/g}' motorrad.jpg

Everything works fine now.


Thanks for your great support

Koala