New Member - First Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New Member - First Question
# 1  
Old 02-18-2010
New Member - First Question

Here is my situation...

System - HP UNIX (HP-UX hq5 B.11.00 U 9000/800 (td))

I have an HL7 (Health Level Seven) pipe-delimied file that does not have any carriage returns/line feeds. I need to insert a line feed before each segment type (MSH, PID, PV1, OBX, etc.) so that my PROGRESS program can read each line and determine the segment type for processing.

Input file looks like this:

Code:
MSH|data|data|data|data|data|data|data|PID|data|data|data|data|PV1|data|data|OBX|data|data|...

I need a command (I've tried sed) to convert the file to look like this:

Code:
MSH|data|data|data|data|data|data|data|
PID|data|data|data|data|
PV1|data|data|
OBX|data|data|...

If anyone can give me a command to do this, I will be most grateful.

Last edited by zxmaus; 02-18-2010 at 03:37 PM.. Reason: added code tags
# 2  
Old 02-18-2010
sed, awk, and other such line-based tools probably aren't going to be much help, they can't handle lines over a relatively small maximum size.

If your shell's read command supports the -d option:
Code:
while read -d '|' DATA
do
        if [ "$DATA" == "MSH" ] || [ "$DATA" == "PID" ] ||
                [ "$DATA" == "PV1" ] || [ "$DATA" == "OBX" ]
        then
                echo -en "\n${DATA}"
        else
                echo -n "|${DATA}"
        fi
done < datafile

echo

# 3  
Old 02-18-2010
Dear Corona,

Thanks for the help but my system does not support the -d option on the read command.

I think you are correct as to why the 'sed' command doesn't work. My HL7 file is almost 1.5 MB.

Any other suggestions?
# 4  
Old 02-18-2010
Could you explain how can we distinguish between segment type and data?
Is it the case - upper/lower?
# 5  
Old 02-18-2010
Quote:
Originally Posted by Corona688
sed, awk, and other such line-based tools probably aren't going to be much help, they can't handle lines over a relatively small maximum size.
I don't think sed has any such limit. It's a stream editor, not a line editor.

Code:
sed 's/|\([MSH|PID|PV1]\)/\|\
\1/g' file1

MSH|data|data|data|data|data|data|data|
PID|data|data|data|data|
PV1|data|data|OBX|data|data|
....

# 6  
Old 02-18-2010
Quote:
Originally Posted by scottn
I don't think sed has any such limit. It's a stream editor, not a line editor.
This is implementation-dependent. GNU sed doesn't. The sed FAQ details what versions have what limitations but it's not clear which version is what HPUX has.

Don't you need -r for brackets and backreferences?
# 7  
Old 02-18-2010
HPUX 11.00

Code:
what /usr/bin/sed

/usr/bin/sed:

         $Revision: 80.5 $

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. What is on Your Mind?

New member

Hi guys! My name is Leonida and I am new here to this forum. Nice meeting you all. (1 Reply)
Discussion started by: leeoona
1 Replies

2. What is on Your Mind?

new member

i am new member i hope here is good friends (1 Reply)
Discussion started by: annsoo
1 Replies

3. UNIX for Dummies Questions & Answers

New Member

HI Bruce from Central PA I have never used Unix but am sick of Microsoft so want to learn it. I use to own a computer store front and training center and stated our with Atari, Commodore and the 1st PC and MS/DOS then Windows BUT sick of Microsoft controlling the computer industry. ... (2 Replies)
Discussion started by: Brucec
2 Replies

4. UNIX for Dummies Questions & Answers

new member need help

brothers and sisters iam a new member of your respectful forum hope to accept me i really would like to an expert in unix and linux so please tell me how could ? and what i should have ? i want to make my project in these subject but i dont know what to do and which... (12 Replies)
Discussion started by: yemen
12 Replies

5. Post Here to Contact Site Administrators and Moderators

Who is The First Member !!!

Hello Admins Just tell me who is the first member of this forum. Regards, Awadhesh (1 Reply)
Discussion started by: Awadhesh
1 Replies

6. Solaris

new member

As a new member how do I go about asking question to the administrator and other users (1 Reply)
Discussion started by: malusims
1 Replies

7. Post Here to Contact Site Administrators and Moderators

member titles

I must have missed it , but what do Junior Memeber/Member mean? is there a reference arounf for the significance of these titles ? Thanks, Hezki (3 Replies)
Discussion started by: me2unix
3 Replies
Login or Register to Ask a Question