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 3 of 8 Topic 2147 of 2236
Post > Topic >>

Re: Multi-line record headers

by ptjm@[EMAIL PROTECTED] (Patrick TJ McPhee) Jan 31, 2008 at 01:56 AM

In article
<83035e9f-37b2-4264-9df0-a1359a007c96@[EMAIL PROTECTED]
>,
 <kevin.byford@[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.

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
%  OE DENNIS ANSZ                   OWNER/EXECUTIVE      600/200-0110
% 
% 00275
%  OE JAMES ARNILD                                       310/755-2079
%  ZA SHARI                         ACCOUNTS PAYABLE     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:

 /^[^ ]/ { customer = $0 }
 /^ / { print customer, $0 }
 !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.

 /^[^ ]/ { customer = $0; needsprinting = 1 }
 /^ / { print customer, $0; needsprinting = 0 }
 !NF && needsprinting { print customer }
 END { if (needsprinting} print customer }
 !NF # this is to preserve blank lines

-- 

Patrick TJ McPhee
North York  Canada
ptjm@[EMAIL PROTECTED]





 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:20:55 CDT 2008.