Fixed Width Join & Pad Sed/Awk Help

I was wondering someone might be able to push me in the right direction, I am writing a script to modify fixed-width spool files, As you can see below the original spool file broke a single line into two for printability sake.

I have had been able do the joins using sed, the thing I am stumbling on is how to properly pad the description field (ex. PODIATRY) to the maximum allowable position so that visually everything still adds up.

I would love to see a sed or awk solution or suggestion, my programming skills aren't as strong as most but I would love to see an efficient solution that I could sink my teeth into and figure out why it does what it does. Thanks in advance!

Input File:

 18 PODIATRY
              539    579.00      54588.73      23284.43         40.21       698    727.00      70887.59      28976.69         39.86
 19 O/P SURGICAL FACILITY
              388    352.00     864494.44     326688.71        928.09       389    385.00    1084639.25     318630.46        827.61
 38 THERAPY
             3111   3642.00     261919.67      61583.00         16.91      3150   3531.00     241123.29      70527.76         19.97
 39 DURABLE MEDICAL EQUIPMENT
 

Output:

 18 PODIATRY                               539    579.00      54588.73      23284.43         40.21       698    727.00      70887.59      28976.69         39.86
 19 O/P SURGICAL FACILITY                  388    352.00     864494.44     326688.71        928.09       389    385.00    1084639.25     318630.46        827.61
 38 THERAPY                               3111   3642.00     261919.67      61583.00         16.91      3150   3531.00     241123.29      70527.76         19.97
 39 DURABLE MEDICAL EQUIPMENT              143    967.00      31939.99      12069.13         12.48       172    976.00      47575.54      20028.77         20.52

kinda 'ugly' ('cause you have the embedded spaces in the SECOND 'field'), but.....

nawk '
  BEGIN {max=25}
  FNR%2{gsub(" ","_");$0=sprintf("%-*s",max,$0);gsub("_", " ");printf;next}
  1' myFile

Thanks for the reply, I seem to be encountering the following error:
nawk: line 3: no arguments in call to printf

your nawk seems finicky :

nawk '
  BEGIN {max=25}
  FNR%2{gsub(" ","_");$0=sprintf("%-*s",max,$0);gsub("_", " ");printf $0;next}
  1' myFile

Thanks! That looks much better, your code should give me the insight I need to massage it further. Thanks again!

Another one:

awk 'NR%2{s=$0;getline;printf("%-25s%s\n", s, $0)}' file

along the same lines as Franklin52:

nawk '
  FNR%2{s=sprintf("%-*s",max,$0);next}
  {printf("%-*s%s\n", max,s,$0)}' max=25 myFile

vgersh99 ...i have a question...

what does

"%-*s"

I haven't found no docs on fmt....

Thanx.

Google for width trick printf

Regards

this is described in 'man -s 3C printf' (at least on Solaris):

     A field width, or precision, or both may be indicated by  an
     asterisk  (*)  .  In this case, an argument of type int sup-
     plies the field width  or  precision.  Arguments  specifying
     field width, or precision, or both must appear in that order
     before the argument, if any, to  be  converted.  A  negative
     field  width  is  taken  as  a - flag followed by a positive
     field width. A negative precision is taken as if the  preci-
     sion were omitted. In format strings containing the %n$ form
     of a conversion specification, a field  width  or  precision
     may  be  indicated by the sequence *m$, where m is a decimal
     integer in the range [1, NL_ARGMAX] giving the  position  in
     the  argument list (after the format argument) of an integer
     argument containing the field width or precision, for  exam-
     ple:

     printf("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);

     The format can contain either numbered  argument  specifica-
     tions (that is, %n$ and *m$), or unnumbered argument specif-
     ications (that is, % and *), but normally not both. The only
     exception to this is that %% can be mixed with the %n$ form.
     The results  of  mixing  numbered  and  unnumbered  argument
     specifications  in  a format string are undefined. When num-
     bered argument specifications are used, specifying  the  Nth
     argument  requires  that all the leading arguments, from the
     first to the (N-1)th, are specified in the format string.

We're just specifying a precision as an 'argument to 'printf' - and not as a 'hard-wired' number in in the first argument to printf:

printf("%-25s", foo)
vs
printf("%-*s", max, foo)   # assuming max=25

A great thanx...

It's clear from now on....