I guess you could try gawk instead.
For debug, replace
if(n != 3) next
with
if(n != 3) {
printf("DEBUG: timestamp in wrong format\n")
next
}
and
if(n != 10) next
with
if(n != 10) {
printf("DEBUG: counts in wrong format\n")
next
}
Adding to your grep (but of course awk can do the grep):
grep 'Session statistics: Requests' * | awk '
BEGIN {
FieldFormat = "%-30s %-25s %6s %7s %7s %6s\n"
printf(FieldFormat,"Job","Time","Added","Updated","Deleted","Errors")...
# code_block.awk
# match the timestamp
#
# Sample:
# Sat Jan 31 01:56:15 2009(abcd .... wxyz)test_has_passed(abcd .... wxyz)
match($0,/^... ... .. ..:..:.. ..../) {
sub("\r\n","")
LastTime = substr($0,RSTART,RLENGTH)
next
}
# print lines found with wq15 until blank or 0D 0A ...
#...
If all you care about is the timestamp to be output whenever your pattern matches, then just keep the last recognized timestamp in a variable of its own and print it when you get your pattern.
Something like:
/^... ... .. ..:..:.. ..../ { #adjust RE to match better...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.