0

I have log files in this pattern -

/mnt/internal-app/logs/internal-app.log_2019-08-20.log.gz
/mnt/internal-app/logs/internal-app.log_2019-08-21.log.gz
..
..
/mnt/internal-app/logs/internal-app.log_2019-08-25.log.gz
..

I would like to get the occurrences of certain text in the files from a certain date range - e.g. 20 to 21.

While following was working for me, to get occurrences of files in the entire range of 20s -

zgrep "search text" /mnt/internal-app/logs/internal-app.log_2019-08-23* 

Trying to get only in the range of 20 to 21, I tried the solution given in
I read https://stackoverflow.com/a/17000211/351903

To make basic regex working, I tried the following, but it does not give me any results -

find . -regex "/mnt/internal-app/logs/internal-app.log_2019-08-23.*" -exec grep 'search text' {} +
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
  • Assuming that you actually have data for August 23 then you might need to escape your forward slashes like this `\/` – MonkeyZeus Aug 29 '19 at 15:31

2 Answers2

1

You could update your pattern to match either a 0 or 1 using a character class:

/mnt/internal-app/logs/internal-app\.log_2019-08-2[01].*

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
1

in addition to answer posted by @The fourth bird

shell allows the following match pattern

[tmp]$ ls internal-app.log_2019-08-2[0123].log.gz
internal-app.log_2019-08-20.log.gz  internal-app.log_2019-08-22.log.gz
internal-app.log_2019-08-21.log.gz  internal-app.log_2019-08-23.log.gz
[tmp]$ ls internal-app.log_2019-08-2{0,1,2,3}.log.gz
internal-app.log_2019-08-20.log.gz  internal-app.log_2019-08-22.log.gz
internal-app.log_2019-08-21.log.gz  internal-app.log_2019-08-23.log.gz
[tmp]$ ls internal-app.log_2019-08-{20,23}.log.gz
internal-app.log_2019-08-20.log.gz  internal-app.log_2019-08-23.log.gz

{} has different behavior between shell file name match and pcre regex

and in this case , i would say it is easier and more accurate with
internal-app.log_2019-08-{19,20}.log.gz
other than internal-app.log_2019-08-[12][09].log.gz

James Li
  • 469
  • 3
  • 7