0

I need your assistance to chop a single continuous line from a log file of HL7 messages, into individual lines such as the following in using Unix commands / Java or Both:

Timestamp   : 20130221 001805
Code        : OUT031
Severity    : F
Component   : cmHL7OutboundBuild_jcdOutboundBuild1/cmHL7OutboundBuild/dpPRODHL7Outbound
Description : Last HL7 Message read <MSH|^~\&|target application|hostname|source application|A212|201302210016||ORM^O01|62877102|D|2.2|||ER
PID||.|0625176^^^00040||JOHN^SMITH^ ||19390112|F||4|address||^^^^^^93271081||||||41253603422
PV1|1||ED^^^40||||||name of physician||||||||physician operator id
ORC|SC||13-4529701-TFT-0|13-4529701|P|||||||name of physician
OBR|1||13-4529701-TFT-0|0360000^THYROID FUNCTION TESTS^1||201302212108|201302212102|||||||201302212108||name of physician||.|||13-4529701|201302210016||department|P||^^^201302212108
>  Exception:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`schema/table`, CONSTRAINT `table_ibfk_request_order_panel` FOREIGN KEY (`fk_gp_latest_request_order_panel`) REFERENCES `gp_request_order_panel` (`gp_request_order_panel_seq`))
SendEmail   : Y

The issue is that all 11 lines are wrapped around in one continuous line which made up a single record, followed by the next record of another 11 lines and so on Solaris 10 Unix server. Yet the same log would display properly when ftped over to a desktop Windows side. As a result, I am looking for a solution, possibly a combination of Unix & Java to break down each record of 11 lines on their own and the same thing for the next record....

Below is a break down on what I believe need to be done on the Solaris 10 server: ( i ) Would be great if this log could be converted to Windows ASCII format but staying on the Solaris 10 server, like the one being ftped to Windows. When the same file is ftped from Windows back to Solaris 10 server, it reverted back to its original 1 continuous line format. ( ii ) Otherwise, break it down line by line or insert and end of line but where to?

I have tried various Unix string manipulated commands such as sed, awk, grep, fold, cut, unix2dos including from Bash: how to find and break up long lines by inserting continuation character and newline? without success.

Your assistance would be much appreciated.

Thanks,

Jack

Community
  • 1
  • 1
George Smith
  • 289
  • 1
  • 8
  • 17

1 Answers1

0

This is a windows text file (windows carriage control) since it displays ok in Windows but not UNIX.

Solaris has a dos2unix command to handle this issue.

dos2unix filename > newfilename

Try that. To see what I mean use the vi editor on "filename" in the example above. You will see ^M characters in the file. UNIX does not use those for formatting lines.

If you have the vim editor it will read "long lines". Or try od -c < filename | more to see the ^M or ascii 13 characters. od will show them as \r I'm reasonably sure the issue is that the carriage control on the file prevents UNIX from seeing the lines. Try the od approach.

jim mcnamara
  • 16,005
  • 2
  • 34
  • 51
  • Hi Jim, Thanks for offering your assistance. dos2unix filename > newfilename didn't help. Part of the problem is not being able to read this file in vi editor since it is too long with "log.txt" [Read only] Line too long" Are you sure we should try dos2unix as opposed to unix2dos since we are trying to insert ^M characters to log.txt don't we? Any other suggestion? Thanks, Jack – George Smith Dec 25 '13 at 23:55
  • If you have the vim editor it will read "long lines". See edit to post. – jim mcnamara Dec 26 '13 at 03:27