New Member - First Question


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

I don't think my original sed worked that great!

Code:
sed -E 's/(PID|PV1|...|...)/\
&/g' file1

But I just ran a test on a line with 7 million characters with no problems, so I imagine the limitations to which you refer are for old versions of sed (so it probably doesn't work on Solaris!!)

Edit: Completely over-looked (i.e. didn't see) first line of question : "System - HP UNIX (HP-UX hq5 B.11.00 U 9000/800 (td))". Smilie Sorry.

Last edited by Scott; 02-18-2010 at 05:48 PM..
# 9  
Old 02-18-2010
It should be straightforward with Perl.
# 10  
Old 02-18-2010
Code:

/usr/bin/sed:
$Revision: 80.5.1.1 $
PATCH_11_00: sed0.o sed1.o hpux_rel.o 00/11/27

# 11  
Old 02-18-2010
If you don't mind an amateurish attempt, how about something like:

Code:
awk '{gsub("MSH","\nMSH",$0) ; gsub("PID","\nPID",$0) ; gsub("PV1","\nPV1",$0) ; gsub("OBX","\nOBX",$0) ; print}' filename

Or, a little easier to expand as needed, perhaps:

Code:
awk 'BEGIN {str[1] = "MSH" ; str[2] = "PID" ; str[3] = "PV1" ; str[4] = "OBX"} \ 
{for (i = 1 ; i <= length(str) ; i++) {gsub(str[i],"\n"str[i],$0)}} \ 
END {print}' filename

Of course, that'll get very tedious depending on how many possible str values therer are...
# 12  
Old 02-18-2010
The first sed posted by scottn works on HPUX 11.00 for the sample file albeit with the trailing pipe character on all but the last record.
The later version with "-E" gives a syntax error.

Now we need the O/P to try it on a large file.

Knowing the Progress version would help. There are other approaches using a recent Progress 4GL.
# 13  
Old 02-18-2010
If I understood the problem correctly, this is something that should work in PHP:

PHP Code:
<?php
$data
=file_get_contents('./your_data.txt');
$stuff=preg_replace("/\|([A-Z0-9]{3})/","|\n$1",$data);
print 
$stuff;
?>
Output on sample file:

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

# 14  
Old 02-19-2010
Trying treesloth's approach using:
Code:

awk '{gsub("MSH","\nMSH",$0) ; gsub("PID","\nPID",$0) ; gsub("PV1","\nPV1",$0) ; gsub("OBX","\nOBX",$0) ; gsub("ORC",\nORC",$0) ; gsub("OBR","\nOBR",$0) ;
gsub("NTE","\nNTE",$0) ; print}' /care/misc/rad_report

I get the error message:
Code:

syntax error The source line is 1.
The error context is
{gsub("MSH","\nMSH",$0) ; gsub("PID","\nPID",$0) ; gsub("PV1","\
nPV1",$0) ; gsub("OBX","\nOBX",$0) ; >>> gsub("ORC",\ <<< nORC",$0) ; gsub("OBR
","\nOBR",$0) ; gsub("NTE","\nNTE",$0) ; print}
awk: The statement cannot be correctly parsed.
The source line is 1.

My version of PROGRESS is 8.3B

Any other suggestions?

---------- Post updated at 02:06 PM ---------- Previous update was at 01:49 PM ----------

I found the error in my previous code (missing ").

Now the error reads:

Code:

awk: Input line MSH|^~\&|HNAM|HNA|CL cannot be longer than 3,000 bytes.

Any other suggestions?
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