1

I have a log file like this:

my test log line May 18 2024 13:30
my test log line May 19 2024 13:30
my test log line May 21 2024 13:30
my test log line May 22 2024 13:30
my test log line May 23 2024 13:30
my test log line May 24 2024 13:30
my test log line May 25 2024 13:30
my test log line May 26 2024 13:30
my test log line May 27 2024 13:30
my test log line May 28 2024 13:30
my test log line May 29 2024 13:30

The format like $(date '+%B %d %Y %H:%M:%S') and always is as above.

How can I extract the the last N days, let's say last 7 days for example?

Expected output could be like this:

my test log line May 22 2024 13:30
my test log line May 23 2024 13:30
my test log line May 24 2024 13:30
my test log line May 25 2024 13:30
my test log line May 26 2024 13:30
my test log line May 27 2024 13:30
my test log line May 28 2024 13:30
my test log line May 29 2024 13:30

Or it May 21 could be included too.

I googled but could found nothing.

1 Answer 1

0

Super user is not a script writing service, so I'll give you tip only, where to start:

$ n=1;date -d "-${n}days" +"%B %d %Y" will print yesterdays date,
That is the beginning (base) of a search parameter to grep.

1
  • @NomeEoleSem: I would like to point out that there could be problems with the further implementation if the day calculated here has no entry in the Lgfile.
    – Cyrus
    Commented Jun 14 at 3:53

Not the answer you're looking for? Browse other questions tagged .