On 1/31/2008 9:46 AM, William James wrote:
> On Jan 31, 7:28 am, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
>
>>On 1/30/2008 4:48 PM, kevin.byf...@[EMAIL PROTECTED]
wrote:
>>
>>
>>
>>
>>>This one has me stumped. In 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. There are no tabs in the file, just spaces. Some customer
>>>numbers have zero contacts, some have many.
>>
>>>Here's the source:
>>
>>>00270
>>> OE DENNIS ANSZ OWNER/EXECUTIVE 600/200-0110
>>
>>>00275
>>> OE JAMES ARNILD 310/755-2079
>>> ZA SHARI ACCOUNTS PAYABLE 310/755-2079
>>
>>>00300
>>
>>>00310
>>> FX FAX NUMBER 912-1948
>>> GM JOE GENERAL/DIV MGR 376/942-9735
>>
>>>P00315
>>> FX FAX FAX NUMBER 376/788-3443
>>> OE KAREN ZATHO PRESIDENT 317/788-3000
>>> ZP KAREN ZATHO HOME PHONE 317/788-4014
>>
>>>And the goal:
>>
>>>00270 OE DENNIS ANSZ OWNER/EXECUTIVE
>>>600/200-0110
>>
>>>00275 OE JAMES ARNILD
>>>310/755-2079
>>>00275 ZA SHARI ACCOUNTS PAYABLE
>>>310/755-2079
>>
>>>00300
>>
>>>00310 FX FAX NUMBER
>>>912-1948
>>>00310 GM JOE GENERAL/DIV MGR
>>>376/942-9735
>>
>>>P00315 FX FAX FAX NUMBER
>>>376/788-3443
>>>P00315 OE KAREN ZATHO PRESIDENT
>>>317/788-3000
>>>P00315 ZP KAREN ZATHO HOME PHONE
>>>317/788-4014
>>
>>>Any suggestions?
>>
>> awk '/^ /{print k $0;next}{k=$1}' file
>>
>> Ed.
>
>
> This discards customer-numbers that have no contacts.
True. I didn't notice that. I hate when requirements ruin a perfectly good
solution.
awk '/^ /||(/^$/&&f){print k $0;f=0;next}{k=$1;f=1}' file
> Furthermore, it does not print each telephone-number on a line
> by itself.
The OP doesn't want each telephone number on a line by itself, that was
line-wrapping in his first post which he corrected in a followup.
> In addition, it fails to put a blank line between each
> group of contacts.
That's a useless requirement since there no longer needs to be a separator
since
each line is preceeded by the record identifier, but easily fixed if the
OP
REALLY wants it.
Thanks,
Ed.


|