Two IF in one command possible?

Started by Birdman, February 24, 2024, 07:10:49 AM

Previous topic - Next topic

Birdman

Hi there,

I would like to get the following two commands in one command:
exiftool -q -if "${Location} eq ${City}" "-Comment<${Location}, ${CountryCode}" -overwrite_original *.jpg
exiftool -q -if "${Location} ne ${City}" "-Comment<${Location}, ${City}, ${CountryCode}" -overwrite_original *.jpg
Is that possible (working under Windows)? I tried several ways, but none worked for both commands.

Regards,
Martin
Best regards,

Martin (Birdman)

StarGeek

#1
Not as a simple command, as these two -if conditions are opposite and write different values. You would need an if ... then ... else programming structure.

Technically, you could use Perl's ternary operator ( Condition ? True value : False value) and self->GetValue('TAG'), but that is really messy IMO, and would be hard to troubleshoot if something went wrong.  Something like this (Edit: I have not tested this)
exiftool "-Comment<${Location;$_=($_ eq self->GetValue('City')) ? $_ . ',' . self->GetValue('CountryCode') : $_ . ',' . self->GetValue('City') . ',' . self->GetValue('CountryCode')}" file.jpg

Personally, I would just use two commands, as it's easier to figure out what you're trying to do if you have to fix or change it.
"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

Birdman

Quote from: StarGeek on February 24, 2024, 11:49:22 AM... Personally, I would just use two commands, as it's easier to figure out what you're trying to do if you have to fix or change it.
Thank you! I agree, that this seems to be the better way to go.
Best regards,

Martin (Birdman)