ExifTool Forum

ExifTool => Newbies => Topic started by: Jom on July 15, 2019, 03:30:31 PM

Title: Remove custom symbols
Post by: Jom on July 15, 2019, 03:30:31 PM
Hi.

1. I'm trying to create a template to remove spaces and hyphens. Here is my option:
exiftool "-TestName<${Model;s/ //g;s/-//g}" .
But I don't understand the purpose of "g".

2. Also, I don't understand fundamental difference between "tr" and "s" in the example from the documentation:
exiftool -p '${make;tr/ /_/;s/__+/_/g}' image.jpg
What are the cases where we can't use "s" instead of "tr"?
Title: Re: Remove custom symbols
Post by: StarGeek on July 15, 2019, 03:51:03 PM
Quote from: andreikorzhyts on July 15, 2019, 03:30:31 PM
But I don't understand the purpose of "g".

The g stands for global.  Without it the substitution would stop after the first match.  For example if your regex was s/-// (no g), then "if-this-than-that" would be "if this-than-that", while with the g, it would be "if this than that".

Quote2. Also, I don't understand fundamental difference between "tr" and "s" in the example from the documentation:
exiftool -p '${make;tr/ /_/;s/__+/_/g}' image.jpg
What are the cases where we can't use "s" instead of "tr"?

tr is the transliterate operator.  It replaces individual characters only. So if your example make was "Three   Spaces   Inbetween", then tr/ /_/ returns "Three___Spaces___Inbetween".  On the other hand, the other option is regex substitution.  It works likes this s/SearchTerm/Replacement/.  In the example s/__+/_/g it searches for an underscore (_) followed one or more underscores (_+).  The plus sign stands for 1 or more of the previous character.  So this command would take two or more underscores and globally replace them by a single underscore.  "Three___Spaces___Inbetween" becomes "Three_Spaces_Inbetween".
Title: Re: Remove custom symbols
Post by: Jom on July 15, 2019, 04:35:17 PM
Спасибо за ответ.
It is very difficult to learn everything in a foreign language.
Title: Re: Remove custom symbols
Post by: StarGeek on July 15, 2019, 06:36:54 PM
Sorry I can't be more helpful.  I tried to learn Russian years ago and failed spectacularly.  The only thing I remember is, roughly translated, "I don't know", "I don't understand" and "Please pass the glass".
Title: Re: Remove custom symbols
Post by: Jom on July 15, 2019, 07:02:06 PM
Quote from: StarGeek on July 15, 2019, 06:36:54 PM
"Please pass the glass".
You were taught by Russians when you drank vodka? :)
Title: Re: Remove custom symbols
Post by: StarGeek on July 15, 2019, 07:06:33 PM
Heh, nope.  I'm a non-drinker.  I have no idea why that one stuck with me.
Title: Re: Remove custom symbols
Post by: Jom on July 15, 2019, 07:17:49 PM
I'm also a non-drinker and non-smoker.
Real Russians do not drink and are not proud of vodka.
Ещё раз спасибо за ответы.