ZeroLoop ZeroLoop - 1 month ago 8x
Linux Question

How to grep log files during a specific time period

Okay, So i have log files and I would like to search within specific ranges. These ranges will be different throughout the day. Below is a piece of a log file and this is the only piece I can show you, sorry work stuff. I am using the cat command if that matters.

Working EXAMPLE :

cat /dir/dir/dir/2014-07-30.txt | grep *someword* | cut -d',' -f1,4,3,7

2014-07-30 19:17:34.542 ;; (p=0,siso=0)

The above gets me the info I need along with the time stamp, but shows all time ranges and that is what I would like to correct. Lets say I only want ranges of 18 to 20 in the first column of the time.

Actual -->
2014-07-30 19:17:34.542 ;; (p=0,siso=0)

Only range I am looking for -->
[18-20]:00:00.000 ;; (p=0,siso=0)

I am not worried about the
s as they can be any digit.

Thanks for looking. I have not used much in the way of scripting as you can tell from my example, but any help is greatly appreciated.

I have included a log file, the colons and commas are where they should be.

2014-07-30 14:33:19.259 ;; (p=0,ser=0,siso=0) IN ### Word:Numbers=00000,word=None something goes here and here (something here andhere:here also here:2222),codeword=8,codeword=0,Noideanumbers=00000000,something=something, ;;


I have found the answer in the form I was looking for:

cat /dir/dir/dir/2014-07-30.txt | grep *someword* | cut -d',' -f1,4,3,7 | egrep '[^ ]+ (2[0-2]):[0-9]'

The following command gets me all the information I need from the cut, and greps for the someword I need and with the egrep I can search the times I need.