0

I have a timelapse cam taking pictures every few minutes, no matter if its day or night. I want to pass only the daytime images to ffmpeg to create a movie. So I have a folder full of images with their timestamps in the filename:

photo_2023-02-24_10-48-23.jpg
photo_2023-02-24_03-42.jpg
photo_2023-02-23_23-12-06.jpg
photo_2023-02-23_12-22.jpg
photo_2023-02-23_12-22-03.jpg
...

I want to get all images that were taken in daytime (e.g. between 08-00 and 17-00).

So far I came up with this regex. I want to select the "hour" in the name. How do I reuse that part to compare it in the next step?

find -E . -type f -regex ".*/photo_[0-9]{4}-[0-9]{2}-[0-9]{2}_([0-9]{2}).*" -exec bash -c \
'fn=${0##*/}; h=${HOUR};
 [[ $h -ge 8 && $h -le 17 ]] && echo "$0"' {} \;

Helpful so far: Find all files containing the filename of specific date range on Terminal/Linux

mmoollllee
  • 63
  • 1
  • 1
  • 6
  • Wouldn't `".*/photo_[0-9]{4}-[0-9]{2}-[0-9]{2}_(0[89]|1[0-6]).*"` do the trick for you without `-exec`? – markalex Mar 31 '23 at 13:38

1 Answers1

1

If you want to get all files containing number from 08 to 16 (including) in hour position, you could use this command:

find . -type f -regex ".*/photo_[0-9]{4}-[0-9]{2}-[0-9]{2}_(0[89]|1[0-6]).*" 
markalex
  • 8,623
  • 2
  • 7
  • 32
  • True! Thanks for that hint! Still for my couriosity: How could I use the matched hour in exec part? – mmoollllee Mar 31 '23 at 14:28
  • 1
    @mmoollllee, AFAIK, you can't. `-regex` and `-exec` are independent, and information on matching is not transferred. I believe to do something like you described you'd need match filename one more time. – markalex Mar 31 '23 at 14:32