We use this on occasion. It searches back through our archived smats and gives you the date/file that what you are looking for is in. Not sure if it’s exactly whats needed here.
#!/quovadx/qdx5.4.1/integrator/bin/hcitcl
#
##########################################################################################
##########################################################################################
##########################################################################################
#
# A Tcl program to scan the smats in ARCHIVE
# Prints out info for every segment that matches the criteria input
#
# Glob matching works on
# – File Name
# – Message Type
# – Field Value
#
# Program Name: FindMsgs
#
# Parameterts: None
#
# Example Call: FindMsgs
#
# Created: John Zalesak 04/21/2009
#
#
##########################################################################################
##########################################################################################
##########################################################################################
#
#
proc FindMsgs {argv argc} {
##########################################################################################
# Set up globals and initialize variables
##########################################################################################
global HciRoot
set linecnt 0
set maxlines 60
set FieldVal {}
set fldSep “” ;# Field Seperator – get from MSH
set subSep “” ;# SubField Seperator – get from MSH
set repSep “” ;# Repeating Field Seperator – get from MSH
set segList [list]
set fldList [list]
set subfldList [list]
#########################################################################################
# Load in the arguments we need that were passed from the caller
#########################################################################################
puts -nonewline “nPlease Enter the Site Name: ”
gets stdin SiteNa
puts -nonewline “nPlease Enter the File Name: ”
gets stdin FileNa
puts -nonewline “nPlease Enter the Message Type: ”
gets stdin MsgType
puts -nonewline “nPlease Enter the Segment Name: ”
gets stdin SegNa
puts -nonewline “nPlease Enter the Field Number: ”
gets stdin FieldNu
puts -nonewline “nPlease Enter the Field Value: ”
gets stdin FieldVal
# puts -nonewline “nPlease Enter the Sub-Field Number: ”
# gets stdin SubFieldNu
set linenct 0
foreach match [lsort [glob -nocomplain -dir $HciRoot/ARCHIVE/$SiteNa — $FileNa.*.idx]] {
set idxchan [open $match]
set idxdata [read $idxchan]
set match [string map {idx msg} $match]
set msgchan [open $match]
echo “nFile name: $match”
foreach idxmsg $idxdata {
keylget idxmsg OFFSET MsgOffset
keylget idxmsg LENGTH MsgLength
# echo $MsgOffset
# echo $MsgLength
seek $msgchan $MsgOffset start
set Msg [read $msgchan $MsgLength]
# echo raw message $Msg
set fldSep [string index $Msg 3] ;# Field Seperator
set subSep [string index $Msg 4] ;# Sub-Field Seperator
set repSep [string index $Msg 5] ;# Repeating Field Seperator
set segList [split $Msg n] ;# Split message into segList
set type [lindex [split [lindex [split [lindex $segList 0] $fldSep] 8] $subSep] 1]
if { [string match -nocase $MsgType $type] == 1 } {
foreach seg $segList {
if { [string first “MSH” $seg] == 0 } {
set MsgID [lindex [split [lindex $segList 0] $fldSep] 9]
}
if { [string first $SegNa $seg] == 0 } {
set fldList [split $seg $fldSep]
if { [string match -nocase $FieldVal [lindex $fldList $FieldNu]] == 1 } {
echo “ID = $MsgID – Type = $type – Seg = $SegNa – Field = $FieldNu – Value = [lindex $fldList $FieldNu]”
incr linecnt
if { $linecnt >= $maxlines } {
echo “Press Enter to Continue: ”
gets stdin
echo “nFile name: $match”
set linecnt 0
}
}
}
}
}