Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Multi-line ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 2147 of 2236
Post > Topic >>

Re: Multi-line record headers

by kevin.byford@[EMAIL PROTECTED] Jan 30, 2008 at 06:23 PM

On Jan 30, 5:56=A0pm, p...@[EMAIL PROTECTED]
 (Patrick TJ McPhee) wrote:
> In article
<83035e9f-37b2-4264-9df0-a1359a007...@[EMAIL PROTECTED]
>,=A0<kevin.byf...@[EMAIL PROTECTED]
> wrote:
>
> % This one has me stumped. =A0In the below example I'm trying to get the
> % (customer) number (which might also contain capital letters) above
> % each group of contacts to show on every line in front of each
> % contact. =A0There are no tabs in the file, just spaces. =A0Some
customer=

> % numbers have zero contacts, some have many.
>
> The key to solving this kind of problem is to find a reliable way
> to distinguish between the different kinds of data in your input.
>
> % Here's the source:
> %
> % 00270
> % =A0OE DENNIS ANSZ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 OWNER/EXECUTIVE
=
=A0 =A0 =A0600/200-0110
> %
> % 00275
> % =A0OE JAMES ARNILD =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=
=A0 =A0 =A0 =A0 =A0 =A0 310/755-2079
> % =A0ZA SHARI =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ACCOUNTS
PAY=
ABLE =A0 =A0 310/755-2079
>
> From this, it seems that the contract information can be identfied
> by the leading white-space, and the customer number can be identified
> by the leading not-white-space. So, for a start:
>
> =A0/^[^ ]/ { customer =3D $0 }
> =A0/^ / { print customer, $0 }
> =A0!NF # this is to preserve blank lines
>
> The trouble with this is that it throws out the contractless customers.
> I'd handle that by setting a flag.
>
> =A0/^[^ ]/ { customer =3D $0; needsprinting =3D 1 }
> =A0/^ / { print customer, $0; needsprinting =3D 0 }
> =A0!NF && needsprinting { print customer }
> =A0END { if (needsprinting} print customer }
> =A0!NF # this is to preserve blank lines
>
> --
>
> Patrick TJ McPhee
> North York =A0Canada
> p...@[EMAIL PROTECTED]
 - thank you very much.  As an awk newbie I was banging my head all
day on this...  thanks again,

cheers,
-kevin




 8 Posts in Topic:
Multi-line record headers
kevin.byford@[EMAIL PROTE  2008-01-30 14:48:13 
Re: Multi-line record headers
kevin.byford@[EMAIL PROTE  2008-01-30 14:52:55 
Re: Multi-line record headers
ptjm@[EMAIL PROTECTED] (  2008-01-31 01:56:49 
Re: Multi-line record headers
kevin.byford@[EMAIL PROTE  2008-01-30 18:23:36 
Re: Multi-line record headers
William James <w_a_x_m  2008-01-31 00:29:52 
Re: Multi-line record headers
Ed Morton <morton@[EMA  2008-01-31 07:28:15 
Re: Multi-line record headers
William James <w_a_x_m  2008-01-31 07:46:56 
Re: Multi-line record headers
Ed Morton <morton@[EMA  2008-01-31 10:06:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 0:47:11 CDT 2008.