Doing following in testing but also replacing the field seperators – | pipe after OBX.5. with F and I just want OBX.5 to be changed if | appears within OBX.5
set sep [csubstr $msg 3 1] ;# HL7 field separator
set sub [csubstr $msg 4 1] ;# HL7 subfield separator
set segments [split $msg r] ;# Get segments
set outbuf “” ;# Holds outbound message
foreach seg $segments {
if [cequal $seg “”] { continue } ;# Just in case
set segtype [csubstr $seg 0 3] ;# segment type
echo >>>>>> SEGTYPE $segtype
if [cequal $segtype OBX ] { ;# OBX?
set fields [split $seg $sep] ;# Fields
echo >>>>>>>>>>> $fields $seg $sep
set sep “|”
set obx5 [string trimright [join [lrange $fields 5 end] $sep] $sep]
# regsub -all “|” $obx5 “\F\” obx5
regsub -all — {(|)} $obx5 {\F\} obx5
set obx [join [lreplace $fields 5 end $obx5] $sep]