Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types:

  • (H)eader Records
  • (D)etail Records
  • (T)railer Records

The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in length or can be 40, 55, basically any number.

I need an SED or AWK script to somehow take just the Header and Trailer records on the file and append white space to the end until the record becomes 82 bytes long.

Running in C shell.

Example:

H000000000ABCD
D0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
T0000001

Thanks in advance

[UNIX_Help]$ ll input.dat
-rw-r--r-- 1 rick users 114 2009-10-02 14:49 input.dat
[UNIX_Help]$ wc input.dat
  3  16 114 input.dat
[UNIX_Help]$ cat input.dat
HEADER
DETAIL This detail record is exactly eighty-two charcters in total length........
TRAILER record is short.
[UNIX_Help]$ awk -f pad.awk input.dat > output.dat
[UNIX_Help]$ ll output.dat
-rw-r--r-- 1 rick users 249 2009-10-02 14:51 output.dat
[UNIX_Help]$ wc output.dat
  3  16 249 output.dat
[UNIX_Help]$ cat output.dat
HEADER                                                                            
DETAIL This detail record is exactly eighty-two charcters in total length........ 
TRAILER record is short.                                                          
[UNIX_Help]$ 

[UNIX_Help]$ cat pad.awk
{
printf "%-82s\n",$0
}
[UNIX_Help]$ 


awesome, awesome, awesome. Works great.
Thanks so much.:):slight_smile: :slight_smile:

One last question. I have been trying to get this to work in a one liner using execpgm.csh, but I get an error stating missing }. Any ideas???

Below is the actual line I am try to execute in a batch job script using c shell.

execpgm.csh 'awk '{printf "%-82s\n",$0}' $dd_InputEligFile > $dd_OutputEligFile'

Thanks