Search lines between two timestamps in a file

Hi,

I want to pull lines between two timestamps from a file. When I just insert values directly it is working fine.

sed -n '/2014-02-14 05:30/,/2014-02-14 05:31/p' Logfile

When I try to insert variable it is not working.

sed -n '/TZ=GMT+1 date +%Y-%m-%d" "%H:%M:%S/,/TZ=GMT date +%Y-%m-%d" "%H:%M:%S/p' Logfile

Could you please help me how to do this with variable.

Regards
Neethu

Put the commands within $(...) and use " instead of '

sed -n "/$(TZ=GMT+1 date +%Y-%m-%d" "%H:%M:%S)/,/$(TZ=GMT date +%Y-%m-%d" "%H:%M:%S)/p" Logfile

--ahamed

1 Like

Thanks Ahamed for the reply.

It worked as expected.

Regards
Neethu