Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Grep lines between 2 dates in log file

Tags:

linux

bash

shell

I have a log file that looks like this:

2015-07-07 11:23:33,006 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.LoggingInInterceptor@2798240a

name="New Test User"
domicile="A Place"
name="Test User"

2015-07-07 15:00:33,008 DEBUG : Invoking handleMessage on interceptor org.apache.cxf.interceptor.

Now i call my bash script with a paramter like this:

./test.sh -t 2015-07-07,11:00-2015-07-08,20:00.

So my question is: How can i get the text between the two dates in the log file if i use my time range like 2015-07-07 11:00 until 2015-07-08 20:00?

Thanks


1 Answers

sed -n "/2015-07-07 11:23:33/,/2015-07-07 15:00:33/p"

or more general:

sed -n "/$START/,/$END/p"
like image 139
FelixJN Avatar answered Feb 20 '26 04:02

FelixJN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!