complicated date stamp pattern

Hi,

I have a log file which contains lines like below:

2010-07-19 07:13:19,021 ERROR system ...(text)
2010-07-19 07:22:03,427 ERROR system ...(text)
class com... (text)
2010-07-19 07:23:19,026 ERROR system ...(text)
class com... (text)

each line is a separate line... I am given the a
start time such as : "2010 07 17 07 13 19 "
end time such as: "2010 07 19 20 00 00"
and I have 2 variables which puts them to the format of "2010-07-19 07:13:19" and "2010-07-19 20:00:00

I'm not sure what to put such a search pattern to return the log lines in between (inclusive) the start and end times given, and on the example above, it should return lines afters it as well.

if I put the start time and end time of only the first time log line from above it should be:

2010-07-19 07:13:19,021 ERROR system ...(text)

if I put the start time and end time of only the second time log line from above it should be:

2010-07-19 07:22:03,427 ERROR system ...(text)
class com... (text)

if I put the start time and end time of only the third time log line from above it should be:

2010-07-19 07:23:19,026 ERROR system ...(text)
class com... (text)

or if i just put a start and end time including all it should return everything.. etc

This problem is kind of complicated... I would greatly appreciated if anyone can even lead me in the way of getting it to the correct search outputs.

Thanks

I have the following code which, only looks for the start time for exact matches, and returns.

awk -vs="$sstart" '$0~"^"s{p=1}!($0~"^"s) && /^2010/{if(p==1){print "\n"}p=o}p' "$f"

$sstart is the format of "2010-07-19 07:13:19", and $F is the file name.

Hey you can do it this way:

Inside your shell script, let's say the start daytime and end daytime are variables vstart and vend

then add the following in ur shell script:

vend=${vend:-vstart}

sed -n -e '/^'"${vstart}"'/,$p
/^'"${vend}"'/ { 
:up
n
/....-..-.. ..:..:../q
p
b up }' <your log file name>

Thanks for helping, but it's still not working the way i want it to be,

the line

vend=${vend:-vstart}

doesn't seem to do anything, vend is still vend...

---------- Post updated at 12:51 PM ---------- Previous update was at 12:22 PM ----------

Is there any built-in way of getting even a list of the times in between start and end? or do i need to make a function myself to do it specifically?

Thanks

Sorry there is a typo in my code. Please replace it as following:

vend=${vend:-$vstart} ## I missed a $ there

It works like this: if vend is not set then value of vstart is assigned to it.

Thanks, but... vstart and vend will always be set... and how does that help in finding out the lines in between?

vend=${vend:-$vstart}

## the following sed script will stop printing when it finds vend in the log file. 
## So I am setting vend to vstart if you are not providing vend with any input value

sed -n -e '/^'"${vstart}"'/,$p
/^'"${vend}"'/ { 
:up
n
/....-..-.. ..:..:../q
p
b up }' <your log file name>

I am always always always providing a vend value,

this is not what I was looking for at all, but thanks anyways.

Assuming starttime and endtime are shell variables:

starttime="2010 07 19 07 13 19"
endtime="2010 07 19 07 30 00"

awk -F, -v stime="$starttime" -v etime="$endtime" '
BEGIN{gsub(" ","",stime);gsub(" ","",etime)}
/^[0-9]/{
  t=$1
  gsub("[ -:]","",t)
}
t >= stime{p=1}
t > etime{p=0}
p' logfile

Thanks for the input Franklin52, I input the start and end time as follows:

2010 07 19 10 29 00
2010 07 19 10 30 00

and got the following lines from the log file:

2010-07-19 07:37:16
2010-07-19 07:39:00
2010-07-19 07:55:13
2010-07-19 08:00:50
2010-07-19 08:40:04
2010-07-19 08:40:04
2010-07-19 09:18:36
2010-07-19 09:18:36
2010-07-19 09:37:10
2010-07-19 09:37:56
2010-07-19 09:37:56
2010-07-19 09:43:18
2010-07-19 09:43:18
2010-07-19 10:10:31
2010-07-19 10:24:39
2010-07-19 10:28:11
2010-07-19 10:28:11
2010-07-19 10:28:47
2010-07-19 10:28:47
2010-07-19 10:29:00
2010-07-19 10:29:00

I only wanted the last 2 to show up...

| tail -n 2

This is not always the case, if you had read my original problem.. thanks though.

It seems that something is going wrong:eek:

Please proceed here:

http://www.unix.com/shell-programming-scripting/144469-awk-search-pattern.html\#post302455035