ExifTool Forum

ExifTool => Newbies => Topic started by: stackfl0w on March 30, 2020, 04:11:32 AM

Title: commandline pattern matching
Post by: stackfl0w on March 30, 2020, 04:11:32 AM
So my files are named img_YYYYddmm_HHMMSS.jpg and I'm trying to conditionally decide to only process those files that match that format. I try:

exiftool -if "${filename=~/\D+\d{8}_\d{6}\D+/}" (dostuff) ./tmp

But all files fail the condition. I can try making it a substitution with s/// and get it to work but is that really necessary? Any tips?
Title: Re: commandline pattern matching
Post by: Phil Harvey on March 30, 2020, 07:18:46 AM
Your expression has a syntax problem.  The regular expression should be outside the braces:

-if "${filename}=~/\D+\d{8}_\d{6}\D+/"

- Phil
Title: Re: commandline pattern matching
Post by: stackfl0w on April 01, 2020, 12:48:32 AM
doh, thanks!
Title: Re: commandline pattern matching
Post by: stackfl0w on April 02, 2020, 12:24:43 PM
Hey quick question, do elseif statements not work with config files? I always get an error if I try to use any. Don't know if I'm just doing something wrong since I'm new to perl syntax. For instance:


if (expression){
     dosomething;
} elseif (expression){
          dosometehingelse;
          }


Always returns a syntax error. I don't recall the documentation noting it, if I'm mistaken my apologies :)
There's other ways but this is just convenient lol
Title: Re: commandline pattern matching
Post by: StarGeek on April 02, 2020, 12:31:19 PM
Quote from: stackfl0w on April 02, 2020, 12:24:43 PM
Hey quick question, do elseif statements not work with config files?

elsif (https://perldoc.perl.org/functions/elseif.html), not elseif.
Title: Re: commandline pattern matching
Post by: stackfl0w on April 02, 2020, 05:37:04 PM
Ah, saved again from my carelessness! I need to start paying attention to my P's and Q's. Thanks again!
Title: Re: commandline pattern matching
Post by: Phil Harvey on April 02, 2020, 07:26:16 PM
... and E's ...
Title: Re: commandline pattern matching
Post by: stackfl0w on April 03, 2020, 12:30:05 AM
Indeed lol