Extract date from file header and prefix it to all lines

Hello All,
I have a file in the following format. I want to extract the date(020090930, 020090929) in the string "STPAGE020090930" and "STPAGE020090929" and prefix it to all lines below them. The output must be put into a new file.

  STPAGE020090930
xyzz aalc 1+0000000000412600000000090000000000213320000000000000000000000372000000002732832000000000009524
xyzz aalc 200000000000000000000000000000000000000000000000018000000000267475000000000000947
xyzz aalc 3000003579700000000116247300000000000000000000000000000000000000000000000000000000000000000000000000007355
xyzz aclp 1+0000000000080800000000000000000000000000000000000000000000000009000000000044886000000000000315
xyzz aclp 200000000040000000000337500000000000010950000000000000000000000000000000000000000
xyzz aclp 3000000061200000000127983100000000000000000000000000000000000000010000001000000000000017460000000000001460
xyzz aclp 4000001000000
xyzz aclp 568618d102       ogsm          200909240000010000000000000003179bc000000.320000slhq l02 lhq000019         lhq000108
00000000008
  STPAGE020090929
xyzz wstn 1+0000000011820000000000000000000000000000000000000000000000000001000000000003909000000000000084
xyzz wstn 3000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
xyzz wyom 1+0000000000391900000000000000000000000000000000000000000000000000000000000000000000000000000000
xyzz wyom 3000000038100000000011304900000000000000000000000000098800000000000000000000000000000000000000000000000070
00000000004

The desired output is as shown below:

  STPAGE020090930
020090930 XYZZ AALC 1+0000000000412600000000090000000000213320000000000000000000000372000000002732832000000000009524
020090930 XYZZ AALC 200000000000000000000000000000000000000000000000018000000000267475000000000000947
020090930 XYZZ AALC 3000003579700000000116247300000000000000000000000000000000000000000000000000000000000000000000000000007355
020090930 XYZZ ACLP 1+0000000000080800000000000000000000000000000000000000000000000009000000000044886000000000000315
020090930 XYZZ ACLP 200000000040000000000337500000000000010950000000000000000000000000000000000000000
020090930 XYZZ ACLP 3000000061200000000127983100000000000000000000000000000000000000010000001000000000000017460000000000001460
020090930 XYZZ ACLP 4000001000000
020090930 XYZZ ACLP 568618D102       OGSM          200909240000010000000000000003179BC000000.320000SLHQ L02 LHQ000019         LHQ000108
020090930 00000000008
  STPAGE020090929
020090929 XYZZ WSTN 1+0000000011820000000000000000000000000000000000000000000000000001000000000003909000000000000084
020090929 XYZZ WSTN 3000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
020090929 XYZZ WYOM 1+0000000000391900000000000000000000000000000000000000000000000000000000000000000000000000000000
020090929 XYZZ WYOM 3000000038100000000011304900000000000000000000000000098800000000000000000000000000000000000000000000000070
020090929 00000000004

Any help on the above will be appreciated.
Thank you,
John

cat t.pl

while(<>)  {
    if ($_ =~ /STPAGE(.*)/)  {
        $date = $1;
        print $_;
        next;
    }
    print "$date $_";
}

$ perl t.pl input-file

STPAGE020090930
020090930 xyzz aalc 1+0000000000412600000000090000000000213320000000000000000000000372000000002732832000000000009524
020090930 xyzz aalc 200000000000000000000000000000000000000000000000018000000000267475000000000000947
020090930 xyzz aalc 3000003579700000000116247300000000000000000000000000000000000000000000000000000000000000000000000000007355
020090930 xyzz aclp 1+0000000000080800000000000000000000000000000000000000000000000009000000000044886000000000000315
020090930 xyzz aclp 200000000040000000000337500000000000010950000000000000000000000000000000000000000
020090930 xyzz aclp 3000000061200000000127983100000000000000000000000000000000000000010000001000000000000017460000000000001460
020090930 xyzz aclp 4000001000000
020090930 xyzz aclp 568618d102       ogsm          200909240000010000000000000003179bc000000.320000slhq l02 lhq000019         lhq000108
020090930 00000000008
  STPAGE020090929
020090929 xyzz wstn 1+0000000011820000000000000000000000000000000000000000000000000001000000000003909000000000000084
020090929 xyzz wstn 3000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
020090929 xyzz wyom 1+0000000000391900000000000000000000000000000000000000000000000000000000000000000000000000000000
020090929 xyzz wyom 3000000038100000000011304900000000000000000000000000098800000000000000000000000000000000000000000000000070
020090929 00000000004

It is always good to explain, what you tried and the difficulty you are facing, instead of just asking for a solution ?! Isn't it ?!

awk '
  /STPAGE/ { DATE = substr( $1, length($1)-8 ); print; next }
  { print DATE, $0 }
' file1
 
  STPAGE020090930
020090930 xyzz aalc 1+0000000000412600000000090000000000213320000000000000000000000372000000002732832000000000009524
020090930 xyzz aalc 200000000000000000000000000000000000000000000000018000000000267475000000000000947
020090930 xyzz aalc 3000003579700000000116247300000000000000000000000000000000000000000000000000000000000000000000000000007355
020090930 xyzz aclp 1+0000000000080800000000000000000000000000000000000000000000000009000000000044886000000000000315
020090930 xyzz aclp 200000000040000000000337500000000000010950000000000000000000000000000000000000000
020090930 xyzz aclp 3000000061200000000127983100000000000000000000000000000000000000010000001000000000000017460000000000001460
020090930 xyzz aclp 4000001000000
020090930 xyzz aclp 568618d102       ogsm          200909240000010000000000000003179bc000000.320000slhq l02 lhq000019         lhq000108
020090930 00000000008
  STPAGE020090929
020090929 xyzz wstn 1+0000000011820000000000000000000000000000000000000000000000000001000000000003909000000000000084
020090929 xyzz wstn 3000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
020090929 xyzz wyom 1+0000000000391900000000000000000000000000000000000000000000000000000000000000000000000000000000
020090929 xyzz wyom 3000000038100000000011304900000000000000000000000000098800000000000000000000000000000000000000000000000070
020090929 00000000004

I have a different opinion, maybe that's what the OP want :rolleyes:

 awk '/STPAGE/{DATE=substr($1, length($1)-7)}{printf ((!/[a-zA-Z]/)?$0:((/[a-z]/)?RS DATE FS $0:((/[A-Z]/ && NR!=1)?RS $0:$0)))}' file
  STPAGE020090930
20090930 xyzz aalc 1+0000000000412600000000090000000000213320000000000000000000000372000000002732832000000000009524
20090930 xyzz aalc 200000000000000000000000000000000000000000000000018000000000267475000000000000947
20090930 xyzz aalc 3000003579700000000116247300000000000000000000000000000000000000000000000000000000000000000000000000007355
20090930 xyzz aclp 1+0000000000080800000000000000000000000000000000000000000000000009000000000044886000000000000315
20090930 xyzz aclp 200000000040000000000337500000000000010950000000000000000000000000000000000000000
20090930 xyzz aclp 3000000061200000000127983100000000000000000000000000000000000000010000001000000000000017460000000000001460
20090930 xyzz aclp 4000001000000
20090930 xyzz aclp 568618d102       ogsm          200909240000010000000000000003179bc000000.320000slhq l02 lhq000019         lhq00010800000000008
  STPAGE020090929
20090929 xyzz wstn 1+0000000011820000000000000000000000000000000000000000000000000001000000000003909000000000000084
20090929 xyzz wstn 3000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
20090929 xyzz wyom 1+0000000000391900000000000000000000000000000000000000000000000000000000000000000000000000000000
20090929 xyzz wyom 300000003810000000001130490000000000000000000000000009880000000000000000000000000000000000000000000000007000000000004