Here is what I used to kill multiple OBX segments I do not want based on OBX3 value. I did not bother to correct the segment counts in OBX2:
run {
#Set typical variables
keylget args MSGID mh
set msg [msgget $mh]
set fieldSep [string index $msg 3]
set subFieldSep [string index $msg 4]
set segmentList [split $msg \r]
set msgTRIG [getField $msg MSH 8 1]
#Remove any OBX segment with a value of “Text Report File Name”
set segCnt [llength $segmentList]
for {set i 0} {$i<$segCnt} {incr i} {
set seg [lindex $segmentList $i]
set segFieldLst [split $seg $fieldSep]
set segType [lindex $segFieldLst 0]
set obxType [lindex $segFieldLst 2]
#Remove any OBX that is not a Numeric Value
if {[string equal $segType “OBX”] && [string equal $obxType “Text Report File Name”] } {
set segmentList [lreplace $segmentList $i $i]
set i [expr $i -1]
}
}
#Apply all of the changes to the MH.
set msg [join $segmentList \r]
msgset $mh $msg
lappend dispList “CONTINUE $mh”
}