Main Menu

Sorting keyword list in .csv export

Started by ABRADSHAW, October 24, 2024, 08:57:52 AM

Previous topic - Next topic

ABRADSHAW

As a recent recruit I am looking for a way to sort the order of image keywords exported from Bridge. I have added my keywords to my images and they all appear to be in a logical order when looked at in bridge but do not always appear in the same order in the ExifTool .csv file export.
For example I have in one image folder several dozen images all tagged as "2020s, 2023, Madeira", i.e. an alpha sorted list, but, in my export file, some appear as "2020s,2023,Madeira", others as "2023,Madeira,2020s" and others as "Madeira,2020s,2023", i.e. not a consistent logical sequence. As I wish to use the .csv file for further analysis splitting the keywords out of the multi valued field a consistent order would be helpful.
...or am I missing something.

Phil Harvey

I don't know if this can be done in the GUI, but via the command line you could do this:

> exiftool a.jpg -subject
Subject                         : one, two, three, four
> exiftool a.jpg -p '$filename,"${subject;my @a=split /, /;$_ = join ", ", sort @a}"'
a.jpg,"four, one, three, two"

The output of the second command gives you a CSV with sorted keywords.  I'm on a Mac, so your quoting would be different if you are on Windows.

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

FrankB

Gui doesn't have something like this. I am preparing V636 and that will have an export to CSV, but it will output all in one column like this.

subject.jpg

@Phil: I tried your command and it works. But what if the OP wants every subject in its own column? like this:
columns.jpg

Am I correct that ExifTool handles Subject as an unordered list, but the order is usually 'as inserted'? And if that's true would rewriting the files also be an option?

Phil Harvey

You can put them in separate columns like this (basically just remove the quotes):

exiftool a.jpg -p '$filename,${subject;my @a=split /, /;$_ = join ",", sort @a}'

This will work provided none of the keywords has a comma.  But if it does the API Filter option may be used to quote the necessary keywords.

ExifTool treats all lists the same way, and maintains the order.  Yes, you could rewrite the file to change the order.

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

FrankB

Thanks Phil.

I asked to find out if something needed to be added to GUI, but I dont think I can.

Frank

ABRADSHAW

Thanks Phil & Frank for your input I will have a play and see what I can achieve splitting them into separate columns but this will still be only a partial answer.
You are correct in that the Keywords from Bridge appear in the order they were appended to the images. Probably very useful somewhere I'm sure but in a structured hierarchical type list of questionable value. Re-classifying several thousand images would be a herculean task and remembering to do it in exactly the same way in the future without any inadvertent mistakes would be difficult.
I want to be able to extract the keywords in a sorted format, either as one string or as separate columns, in a csv file to be able to import them into a spreadsheet that allows me filter using their values.
I typically attach a couple of date values and then some subject values as shown below:

2024, Garden, 2020s, House 61, Home
2020s, 2024, Garden, House 61, Home
Imperial War Museum, 2024, 2020s, Places & Events

It would be a great help to at least be able to rely on the date values to be consistently in one or 2 places in the export; if alphanumeric, then in col 1 and 2. the others could be dealt with later.

Again thanks for the thoughts so far and any further thoughts would be gracefully received.

Tony


 

FrankB

FYI.

Starting with ExiftoolGui  V6.3.6  you can export the file list details to CSV.

You can customize the user defined view, to include the fields you need, and in Preferences you setup the separator character for list-type fields.

This does not solve your question to split the list field in separate fields, but it might help you to quickly check the data.

Frank

ABRADSHAW

Hi Phil
I have been experimenting with the split/sort command line suggested above as it looks to be a very useful option to sort keywords combined with some judicious re-naming of the keywords to make the order irrelevant.

The command line i have used is

exiftool "Canons Ashby (18).JPEG" -p '$filename,${subject;my @a=split /, /;$_ = join ",", sort @a}'

It works in that it gives me the printout of the filename and the subject (keywords) but then descends into a series of errors for the remainder of the line seemingly starting at @a, it reports

Error: File not found - @a=split
Error: File not found - /,
Error: File not found - /;$_
Error: File not found - =
Error: File not found - join
Error: File not found - ,,
Error: File not found - sort
Error: File not found - @a}'
    1 image files read
    8 files could not be read

I have spent some time playing with the syntax and looking through the on-line documentation but have not been able to improve upon the initial result.

Can you please help a very green novice further??

Tony

StarGeek

Quote from: ABRADSHAW on November 21, 2024, 09:33:48 AMCan you please help a very green novice further??

Read the very bottom of Phil's post.

He listed the Mac/Linux version of the command, which would be correct for him because he's on a Mac.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype