Prepend filename to each data row extracted by exiftool

Started by swiss_knight, March 09, 2023, 10:28:59 AM

Previous topic - Next topic

swiss_knight

Hello.

I am extracting image metadata in a bash script over multiples images (many thousands).

The exiftool command is as follow within a for loop over files:

exiftool -a -G0 --EXIF:IFD1:all -s "${file}" > output.txt
Because the ">" operator actually appends each exiftool output per image to the same file, I would like to differentiate tags and their values per image, in row-wise manner, so instead of such content:

ExifTool :      ExifToolVersion                 : 12.57
File :          FileName                        : 201510_16.JPG
File :          Directory                       : /app/data/images/folder1
File :          FileSize                        : 856 kB
File :          FileModifyDate                  : 2004:03:15 13:12:00+01:00
File :          FileAccessDate                  : 2023:03:09 10:48:32+01:00
File :          FileInodeChangeDate             : 2023:03:02 15:05:45+01:00
File :          FilePermissions                 : -rw-rw-r--
File :          FileType                        : JPEG
File :          FileTypeExtension               : jpg
...


I would like to prepend each line with the corresponding file name (as found in the File:FileName tag):

201510_16.JPG :    ExifTool :      ExifToolVersion                 : 12.57
201510_16.JPG :    File :          FileName                        : 201510_16.JPG
201510_16.JPG :    File :          Directory                       : /app/data/images/folder1
201510_16.JPG :    File :          FileSize                        : 856 kB
201510_16.JPG :    File :          FileModifyDate                  : 2004:03:15 13:12:00+01:00
201510_16.JPG :    File :          FileAccessDate                  : 2023:03:09 10:48:32+01:00
201510_16.JPG :    File :          FileInodeChangeDate             : 2023:03:02 15:05:45+01:00
201510_16.JPG :    File :          FilePermissions                 : -rw-rw-r--
201510_16.JPG :    File :          FileType                        : JPEG
201510_16.JPG :    File :          FileTypeExtension               : jpg
...


How could I achieve that, if possible?

Thanks.

----
OS: Ubuntu 22.04
Exiftool 12.57

StarGeek

Exiftool can't directly do this.  But there are a lot of options for creating better output.

You appear to be running exiftool once per file.  This is Common Mistake #3. Exiftool's biggest performance hit is the startup time, so running exiftool once over each file will significantly increase the processing time. Exiftool's built in batch processing is very powerful on it's own and looping it is almost never needed.  As an example, on a recent Reddit post, a person listed a script they used looping exiftool once per file on over 5,000 files.  This took over an hour.  Using exiftool's built in batch processing, the command I used to do the same thing took a little over 6 minutes (6 minutes, 506 milliseconds to be exact).

Exiftool has a lot of options for editing the output.  I would think the -csv option might be a good match.  You would get the filename as the first entry of a row, followed by all the data you are extracting.  FAQ #12 also gives some tips on this.

Alternatively, you create your own format using the -p (-printFormat) option.  You would have to name exactly which tags you want to output, so you couldn't use -EXIF:All, but you would have complete control over the output.

There is also the -j (-json) option and the -X (-xmlFormat) option for output the data.
"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