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


|