How do I get only a tag value from exiftool output in Bash?
Asked 11/13/2014
1 views
2 answers
0
I want to capture the camera make in a Bash variable using exiftool, but the default output includes the tag name and colon. For example, exiftool -make x.jpg returns Make : SAMSUNG. How can I make exiftool print only the tag value so I can assign it cleanly to a variable?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
11y ago
2 Answers
35
From the man page:
-s[NUM] (-short)
Short output format. Prints tag names instead of descriptions.
Add NUM or up to 3 -s options for even shorter formats:
-s1 or -s - print tag names instead of descriptions
-s2 or -s -s - no extra spaces to column-align values
-s3 or -s -s -s - print values only (no tag names)
-S (-veryShort)
Very short format. The same as -s2 or two -s options.
Tag names are printed instead of descriptions, and no extra
spaces are added to column-align values.
So, any of the following will work:
exiftool -s -s -s -make x.jpg
exiftool -s3 -make x.jpg
exiftool -s -S -make x.jpg
Note that combining multiple -s options into -sss, such as increasing -v/-vv/-vvv verbosity in some Linux/Unix command line utilities such as tcpdump, will not work.
Originally by user1943. Source · Licensed CC BY-SA 4.0
user1943
11y ago
0
Generated from our catalog & community — verify before relying on it.
Use exiftool’s short-output mode that prints values only:
exiftool -s3 -make x.jpg
That outputs just:
SAMSUNG
Equivalent forms are:
exiftool -s -s -s -make x.jpg
exiftool -s -S -make x.jpg
You can then assign it in Bash like:
make=$(exiftool -s3 -make x.jpg)
Other options mentioned by users include -b and -T, which can also suppress the tag label in some cases, but -s3 is the clearest and most direct choice for plain text tag values.
Recommended products
UniqueBot
AI11y ago
Your Answer
Related Questions
How do I include a shell variable in an ExifTool rename path?
Can digiKam remove parent tags when I assign a deeper hierarchical tag?
Can exiv2 delete an EXIF tag by hexadecimal ID if the tag name is unknown?
How do I make digiKam apply parent tags automatically in a hierarchical tag tree?
In digiKam, how do you confirm an existing face tag after typing its name?