In Tcl it is easy enough. Jim may have an Xlate method
I will assume you know how to split an HL7 message in Tcl.
Assume sements are in variable segList and separator characters were captured similar to:
set fldSep [string index $msg 3]
set subSep [string index $msg 4]
set iterSep [string index $msg 5]
sep loc [lsearch -regexp $segList {^PV1}]
set pv1 [split [lindex $segList $loc] $fldSep]
set fld19 [split [lindex $pv1 19] $iterSep]
# if order in the list is not important then:
set fld19 [join [lsort -unique $fld19] $iterSep]
# to maintain order (assuming you have Tcl 8.6):
foreach element $fld19 {dict set tmp $element}
set fld19 [join [dict keys $tmp] $iterSep]
# then:
set pv1 [lreplace $pv1 19 19 $fld19]
set segList [lreplace $segList $loc $loc [join $pv1 $fldSep]]
msgset $mh [join $segList r]
return “{CONTINUE $mh}”
Be advised I can and do fat finger some things this is off the top of my pointed head