1

I want to extract the log messages between two dates. The problem is that the date format is as below.

[tthangavel@localhost test]$ cat file
May 1 06:00:08 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,E,RTT,125,50,200,5,601,17635626,50,15841153,4928488,14274344,0,-,17560
May 12 06:00:08 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,E,RTT,125,50,200,5,601,17635626,50,15841153,4928488,14274344,0,-,17560
May 13 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,55,50,200,5,813,10000000000,96,22859361,5306968,19470856,0,-,17559
May 14 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,762,10000000000,96,17805577,4979448,13233936,0,-,17559
May 15 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,848,10000000000,96,19767812,5691888,14387304,0,-,17559
Jun 10 06:00:08 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,E,RTT,125,50,200,5,601,17635626,50,15841153,4928488,14274344,0,-,17560
Jun 11 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,55,50,200,5,813,10000000000,96,22859361,5306968,19470856,0,-,17559
Jun 15 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,762,10000000000,96,17805577,4979448,13233936,0,-,17559
Jul 10 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,55,50,200,5,813,10000000000,96,22859361,5306968,19470856,0,-,17559
Jul 14 06:00:07 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,848,10000000000,96,19767812,5691888,14387304,0,-,17559
Jul 15 06:00:06 localhost my_process: MyField,BRAS_VCI,1,1,10000000,10000000000,-,RTT,56,50,200,5,968,10000000000,96,20602499,4746960,20327184,0,-,17559

I tried the below, but got error.

[tthangavel@localhost test]$ cat file | awk -vBegin=$(date -d"Jun 14 05:39:00" +%s) 'system("date -d\"$1 $2 $3\" +%s") > Begin {print $0}'
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
1468900800
Thirupathi Thangavel
  • 2,418
  • 3
  • 29
  • 49

1 Answers1

2

If lines in the log file are ordered by date (as seems likely), sed will do the job nicely

$ begin='May 12'; end='Jun 15'
$ sed -ne "/^$begin/,/^$end/p" input
James K. Lowden
  • 7,574
  • 1
  • 16
  • 31
  • Thanks! But this requires that a log message of that exact start and end date to be present in the log file. Here, this will not work if there is no log message with date "May 12" or "Jun 15" – Thirupathi Thangavel Jul 28 '16 at 09:38