Exiftool: batch-write metadata to JPEGs from text file Exiftool: batch-write metadata to JPEGs from text file shell shell

Exiftool: batch-write metadata to JPEGs from text file


If you can change the format to a CSV file, then exiftool can directly read it with the -csv option.

You would have to reformat it in this way. The first row would have to have the header of "SourceFile" above the filenames and "Keywords" above the keywords. If the filenames don't include the path to the files, then command would have to be run from the same directory as the files. The whole keywords string need to be enclosed in quotes so they aren't read as a separate columns. The result would look like this:

SourceFile,Keywords001.jpg,"KeywordA, KeywordB, KeywordC"002.jpg,"KeywordD, KeywordE, KeywordF"003.jpg,"KeywordG, KeywordH, KeywordI"004.jpg,"KeywordJ, KeywordK, KeywordL"005.jpg,"KeywordM, KeywordN, KeywordO"

At that point, your command would be
exiftool -csv=/path/to/file.csv -sep ", " /path/to/files

The -sep option is needed to make sure the keywords are treated as separate keywords rather than a single, long keyword.

This has an advantage over a script looping over the file contents and running exiftool once for each line. Exiftool's biggest performance hit is in its startup and running it in a loop will be very slow, especially on a large amount of files (see Common Mistake #3).

See ExifTool FAQ #26 for more details on reading from a csv file.


I believe the answer by @StarGeek is superior to mine, but I will leave mine for completeness and reference of a more basic, Luddite approach :-)

I think you want this:

#!/bin/bashwhile IFS=': ' read file keywords ; do    exiftool -sep ", " -iptc:Keywords="$keywords" "$file"done < list.txt

Here is the list.txt:

001.jpg: KeywordA, KeywordB, KeywordC 002.jpg: KeywordD, KeywordE, KeywordF003.jpg: KeywordG, KeywordH, KeywordI

And here is a result:

exiftool -b -keywords 002.jpgKeywordDKeywordEKeywordF

Many thanks to StarGeek for his corrections and explanations.