Need to add CR at the end of each segment

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library Need to add CR at the end of each segment

  • Creator
    Topic
  • #53522
    Yvonne Gaffney
    Participant

    Does anyone have a script that will add a CR at the end of each segment?

    Thanks  😯

Viewing 3 reply threads
  • Author
    Replies
    • #77984
      James Cobane
      Participant

      Yvonne,

      If your segments aren’t already terminated/delimited with a CR, how are your segments delimited so that you know it is a segment?

      James Cobane

      Henry Ford Health

    • #77985
      Yvonne Gaffney
      Participant

      Maybe I should take the time to explain what we are trying to do, since there could be another solution.

      Took a flat file and translated it to hl7, but we did not want all of the records to go to into the database.  I copied the hl7 messages (hcidbdump) to a file which was then given to the user.  They went through the file and removed the messages they did not want to send.  Now they tried using both word and wordpad for this task.  When they save the file and we put it back on the Cloverleaf we are missing the control character; in some cases we lost the CR (word) and in others we lost the NL (wordpad).  Either way, I am trying to figure out how we can do this with some sanity.

      Suggestions on how to save this file without loosing the control characters or the best approach at putting them back in is appreciated.  

      Thanks ❓

    • #77986
      Elisha Gould
      Participant

      assuming there is no new lines that need to be in the message a quick solution is:

      cat file.txt | awk ‘/^MSH/{printf “n%s”,$0} !/^MSH/{printf “r%s”,$0} ‘ > file.msg

      This produces a new line separated message file.

      just as a note might want to delete the first blank line after running this.

    • #77987
      Charlie Bursell
      Participant

      My guess is Windows was trying to be your “friend” and put line feeds to go with the carriage returns.  A simple approach use perl.  If there are multiple records it may take two commands

      perl -pi -e ‘s/n//g’  file

      Then to put linefeeds back after each record

      perl -pi -e ‘s/rMSH/rnMSH/g’ file

      Note that file could be a single file like hl7.dat or multiple files like *.dat

      assumes Unix

Viewing 3 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,448
Topic Tags
288
Empty Topic Tags
10