Note that there are some explanatory texts on larger screens.

plurals
  1. POTCL: How do I group log messages to together based on date stamps
    primarykey
    data
    text
    <p>I'm fairly new to TCL and need some assistance grouping log messages together based on date stamps from a Cisco router.</p> <p>UPDATED: change in sample log. have discovered that there is an extra space when the DD is a single digit. e.g " 1"</p> <p>Samplelog : show logging</p> <pre><code>THREADID: Feb 1 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Feb 1 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Feb 1 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: OFFLINE THREADID: Feb 1 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Feb 3 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: UP THREADID: Feb 3 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: UP THREADID: Feb 4 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Feb 4 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Mar 15 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: UP THREADID: Mar 15 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Mar 15 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Mar 16 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: UP THREADID: Mar 16 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN THREADID: Mar 16 HH:MM:SS.SSS : %TYPE-OF-VAIRBLE: DOWN </code></pre> <p>Desired output </p> <pre><code>Feb 01 || 3 down Feb 04 || 2 down Mar 15 || 2 down Mar 16 || 2 down </code></pre> <p>Updated with new code with new logic to try and address extra space, although this is not working as expected.</p> <pre><code>set y [read -nonewline [set f [open "tmp.txt" r]]]; array set counts [list]; foreach message [split $y "\n"] { # This gets the status, ie: DOWN/UP/OFFLINE. set status [lindex [split $message] end]; # will assign last field set mon [lindex [split $message] 1]; # number represents the filed number set day [lindex [split $message] 2]; if {$day ==""} { set day [lindex [split $message] 3]; } else { set day [lindex [split $message] 2] } # +number represents the counter if {[info exists counts($mon,$day,$status)]} { set counts($mon,$day,$status) [expr {$counts($mon,$day,$status)+1}] } else { set counts($mon,$day,$status) 1 } } # sort based for down type events puts "\n\n MMM DD || Cnt Status" puts " =====================" foreach count [lsort -increasing -unique [array names counts]] { foreach {mon day status} [split $count ","] { break; } if {$status =="down"} { puts " $mon $day || [set counts($count)] \t $status" } } if {[info exists f]} { close $f } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload