0

I want to extract infromation from logs using a shell script for a particular time range . A line in logs looks like this:

[16:34:34:911][13-10-2015]:No free accounts available

I need to extract data in specific intervals. for example in between 16:00 to 17:00 .I am new to shell script.I have tried with grep command . Can anyone suggest me how to do this ?

Vidya
  • 23
  • 3
  • try something like `grep '^\[16:[[:digit:]]\{2,2\}:[[:digit:]]\{2,2\}:[[:digit:]]\{3,3\}\]' input.txt`. note that this wont get entries at 17 on the dot – amdixon Oct 15 '15 at 07:47
  • @amdixon want to do it periodically. So everytime I just need to enter desired time stamp(in between particular seconds or mins or hours too) to extract the logs between those time stamp from logs. – Vidya Oct 15 '15 at 08:14
  • and `grep '^\[16:3' input.txt` or when you want exact date as well `grep '^\[16' input.txt | grep '\[13-10'` This will return you the lines that start with 16 hours, and from that output it will grep the date 13-10 if you need it like that. Or if you want to use AND with grep , in case lets say you want 16h and 17 together : `grep '^\[16\|^\[17' input.txt` – B.Kocis Oct 15 '15 at 10:43

0 Answers0