1753544 Members
5964 Online
108795 Solutions
New Discussion

awk Separating Records

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: awk Separating Records

Hi (again) Nash:

> James' solution works fine but I cant figure out how to append | to the subsequent lines using perl.

OK, try this:

# perl -0377 -wne 's/\012//g;@a=split(/(?=1\|I\||1\|D\||1\|U\|)/,$_);for $b (@a) {print "NEW RECORD:$b|\n\n"}' audit.log

I suspect that you want to drop the "NEW RECORD:" preamble and the additional newline ('\n') that I added for clarity, so:

# perl -0377 -wne 's/\012//g;@a=split(/(?=1\|I\||1\|D\||1\|U\|)/,$_);for $b (@a) {print "$b|\n"}' audit.log

1|D|hfoo01||39322|74883|service-call-master2|call-no|1438143|call-status|D|F3|ca
ll-date-last-change|20-AUG-2007|30-AUG-2007|
1|U|hfoo01||39322|74893|service-call-master2|call-no|1438143|call-user-only-num1
|0.0000|23158.0000|
1|I|hfoo01||39322|74893|job-cost-master2|job-code|1438143|jcm-project-manager|GN
OHPH01|HFOO01|
1|U|hfoo01||39322|74903|service-call-master2|call-no|1438143|call-invoice-no||S3
106895|

Regards!

...JRF...

Dennis Handly
Acclaimed Contributor

Re: awk Separating Records

>except for the first record which missed a "|" and the fourth record which is totally missing.

You need to adjust the BEGIN to add that "|".
And you lost my END to print out the last record.