Author Topic: commandline pattern matching  (Read 226 times)

stackfl0w

  • Newbie
  • *
  • Posts: 9
commandline pattern matching
« 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:

Code: [Select]
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?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: commandline pattern matching
« Reply #1 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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

stackfl0w

  • Newbie
  • *
  • Posts: 9
Re: commandline pattern matching
« Reply #2 on: April 01, 2020, 12:48:32 AM »
doh, thanks!

stackfl0w

  • Newbie
  • *
  • Posts: 9
Re: commandline pattern matching
« Reply #3 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:

Code: [Select]
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

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3785
Re: commandline pattern matching
« Reply #4 on: April 02, 2020, 12:31:19 PM »
Hey quick question, do elseif statements not work with config files?

elsif, not elseif.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

stackfl0w

  • Newbie
  • *
  • Posts: 9
Re: commandline pattern matching
« Reply #5 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!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: commandline pattern matching
« Reply #6 on: April 02, 2020, 07:26:16 PM »
... and E's ...
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

stackfl0w

  • Newbie
  • *
  • Posts: 9
Re: commandline pattern matching
« Reply #7 on: April 03, 2020, 12:30:05 AM »
Indeed lol