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

Re: Multi-line record headers

by William James <w_a_x_man@[EMAIL PROTECTED] > Jan 31, 2008 at 12:29 AM

On Jan 30, 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?

We want the record-separator to be an empty line.

BEGIN { RS = "" ; FS = "\n" }

1==NF { print $0 ORS; next }

{ for (i=2; i<=NF; i++)
  {
    tel = $i ; sub( /.* /, "", tel )
    sub( / +[^ ]+$/, "", $i )
    print $1 $i
    print tel
  }
  print ""
}

--- output ---
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




 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 Fri May 16 23:44:58 CDT 2008.