#!/bin/sh
# -*- tcl -*-
# The next line is executed by /bin/sh, but not tcl \
exec wish "$0" ${1+"$@"}
puts "Start dir [pwd]"
puts [info script]
cd [file dirname [info script]]
puts [pwd]
puts "Files: [glob *.txt]"
foreach file [glob *.tcl] {
    puts -nonewline "$file -- "
}
set inputfile [open messages.1.txt r]
puts $inputfile
# One pass
# set dataList [split [read $inputfile] \n]
# Two steps
set data [read $inputfile]
set dataList [split $data \n]
close $inputfile

puts [string range $data 0 1000]

puts [lrange $dataList 0 5]
puts [list a b c]
puts [list a b [list with sublist]]
set tmplist [list a "b c" d]
puts "TMP: $tmplist"
puts [lreplace $tmplist 0 1 start second third fourth]
puts "TMPLIST: $tmplist"
set newtmplist [lreplace $tmplist 0 1 start second third fourth]
puts "NEW: $newtmplist"

foreach line [lrange $dataList 0 50] {
    set pos [lsearch $line "sshd*"]
 #   puts "$pos: $line"
    if {$pos > 0} {
        # Process an ssh line
        # New list:
        # lappend newSSHlist $line
        set name [lindex $line $pos]
        set nameList [split $name {][}]
        puts "NAME: $name NAMELIST: $nameList "
        lassign $nameList name pid
        incr counts($name,$pid)
    }
}
parray counts
exit