Insert 0D 0A after each msg

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Insert 0D 0A after each msg

  • Creator
    Topic
  • #51070
    Alka Sharma
    Participant

    Hi Everyone,

    We have a source system that can send an OBX up to 80 characters but the receiving system can only take OBX segments up to 76 characters. I have written a code which counts the length of OBX’s and create a new OBX if the size if over 76 chracters without breaking the word.

    The issue is to run last two months of messages through my new code. I do not have the smat files in the engine anymore. The source system can only provide me with txt file of messages (each day) which contains 0d after each segment and message. The source system cannot give me a 0D 0A after a message.

    Is there a way to read the file in cloverleaf and write a proc which looks for MSH and insert 0A.

    Thanks in advance.

Viewing 9 reply threads
  • Author
    Replies
    • #68674
      Levy Lazarre
      Participant

      Alka,

      Since the sending system is already sending 0D after each message, you just have to add the additional 0A before each MSH header.

      In your TPS Inbound Data, you could add a TCL script that does something like:

      # Replace “MSH|” by “linefeedMSH|”

      regsub -all — “MSH\|” $msg “x0aMSH|” newmsg

      # The above causes an unnecessary linefeed before the first MSH; remove it.

      set newmsg [string trimleft $newmsg]

      # newmsg now contains the messages with the linefeeds added.

      If you prefer, you can do this outside of the engine with a script like this:

      # Code to add a linefeed in front of all MSH, except the first one.

      set inputfile “C:/test/testbatch.txt”

      set fd [open $inputfile r]

      set wholefile [read $fd]

      close $fd

      # Replace “MSH|” by “linefeedMSH|”

      regsub -all — “MSH\|” $wholefile “x0aMSH|” newmsg

      # The above causes an unnecessary linefeed before the first MSH; remove it.

      set newmsg [string trimleft $newmsg]

      # Write the updated messages to an output file.

      set outfile “C:/test/newbatch.txt”

      set fd [open $outfile w]

      puts -nonewline $fd $newmsg

      close $fd

      I hope this helps.

      –Levy

    • #68675
      Nate Kruse
      Participant

      If you want to do it by hand, open each file in WinVi ( http://www.winvi.de/en/ ).

    • #68676
      Alka Sharma
      Participant

      Thanks so much Nate and Levy

    • #68677
      Bob Richardson
      Participant

      Don’t forget to add a final OA at the end of the file for the last message.

      Check that the last message, last segment ends with 0D 0A.

      Sometimes overlooked.

      Good luck.

    • #68678
      Chris Williams
      Participant

      Looking at this from a slightly different perspective, you can change your regsub to look for “x0dMSH” and convert to “x0dx0aMSH” which will eliminate the issue of starting the file with an empty message. If you get rid of the “-nonewline” in your puts, it will write out the x0a at the end of the last message.

    • #68679
      Russ Ross
      Participant

      When I want to preprocess a data file like you are describing I often just use a perl command to do the job.

      So if you are saying your file is like this

      MSH…message1…rMSH…message2…rMSH…etc…

      and you want it to look like this

      MSH…message1…rn

      MSH…message2…rn

      MSH…etc…

      then I would use a perl command like this at the UNIX prompt

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

      Here is a sample of using this perl command in a KSH script to preprocess all the files in a directory called /hcitest/russ:

      Code:

      #!/usr/bin/ksh

      # since this script changes the files in place
      # be sure to work with a copy of the original files
      # and keep a backup copy of the original files
      # until you feel it is safe to delete them

      myWorkDIR=/hcitest/russ

      cd $myWorkDIR

      files_to_process=`ls -1 * 2>/dev/null | sort`

      for file in $files_to_process; do
         echo “processing file ($file)”
         perl -pi -e ‘s/rMSH/rnMSH/g’ $file
      done

      Russ Ross
      RussRoss318@gmail.com

    • #68680
      Alka Sharma
      Participant

      Thanks for your input Russ. We are not on AIX. Our site is on cloverleaf 5.6 rev 2 on windows server 2003.

      To run this script – do I need to install some perl toolkit on windows server?

    • #68681
      Russ Ross
      Participant

      Sorry, I don’t do windows.

      I believe perl can be run on windows but I’ve never investigated doing it.

      Perhpas someone on the forum can respond to that or you might be able to google for it depending on how much interest you have and effort you want to expend.

      Russ Ross
      RussRoss318@gmail.com

    • #68682
      Gary Atkinson
      Participant

      Try activestate.

    • #68683
      David Barr
      Participant

      I like Cygwin.

Viewing 9 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10