Copying Information from One File to Another File in Shell

Hello, I'm new to scripting and I need help moving text from one file to another file. Here are examples what the files look like.

File 1:

Ac-223     2.10m A             1      0      0     0 Fr-219    358 9.9000E-01             0        0.0             0        0.0             0        0.0 6.6720 0.02536 0.01903   7 118   0  297  29 223.019136 3.739E-183.739E-18
Ac-224     2.78h ECA         482      0      0     0 Ra-224    820 9.0900E-01 Fr-220    359 9.1000E-02             0        0.0             0        0.0 0.5662 0.04901 0.23248  15 211   0  398  29 224.021722 2.304E-172.304E-17
Ac-225     10.0d A          1165      0      0     0 Fr-221    360 1.0000E+00             0        0.0             0        0.0             0        0.0 5.8919 0.02476 0.01708   7 157   0  526  44 225.023229 6.777E-186.777E-18
Ac-226    29.37h B-ECA      1944      1      0     0 Th-226   1108 8.3000E-01 Ra-226    822 1.7000E-01 Fr-222    361 6.0000E-05             0        0.0 0.0003 0.29143 0.13271  14 140   5   99   1 226.026097 1.048E-171.048E-17
Ac-227   21.772y B-A        2205    114      0     0 Th-227   1109 9.8620E-01 Fr-223    362 1.3800E-02             0        0.0             0        0.0 0.0692 0.01502 0.00105  15 185   4  421  19 227.027752 1.009E-181.009E-18
Ac-228     6.15h B-         2869    188      0     0 Th-228   1110 1.0000E+00             0        0.0             0        0.0             0        0.0    0.0 0.44945 0.86714   7 329  54 1465   0 228.031021 3.991E-173.991E-17
Ac-230      122s B-         4725    308      0     0 Th-230   1112 1.0000E+00             0        0.0             0        0.0             0        0.0    0.0 0.92285 0.54396   7 218  42  720   0 230.036289 2.278E-172.278E-17

File 2:

Ac-223        2.10m       480
 2 8.38497E+00 6.06280E-05  X
 2 2.14756E-05 1.04461E-04  X
 2 1.00091E-03 4.27494E-04  X
 2 7.83209E-07 6.59000E-04  X
 2 3.57877E-02 2.82466E-03  X
 2 1.76193E-06 2.93700E-03  X
 2 3.20904E-04 3.59600E-03  X
 2 2.32345E-03 1.04149E-02  X
 2 2.73926E-05 1.07215E-02  X
 2 2.47953E-05 1.13895E-02  X
 2 3.99189E-03 1.18951E-02  X
 2 3.51076E-02 1.20348E-02  X
               [.....]
Ac-224        2.78h       682
 2 1.26364E+00 6.05941E-05  X
 2 1.52234E+01 7.12229E-05  X
 2 3.23790E-06 1.04068E-04  X
 2 4.64062E-05 1.11439E-04  X
 2 1.43848E-04 4.30159E-04  X
 2 1.76238E-03 4.31588E-04  X
 2 4.53773E-07 6.59000E-04  X
 2 2.11568E-06 6.72000E-04  X
 2 5.58834E-03 2.81326E-03  X
 2 7.80547E-02 2.88379E-03  X
 2 1.99037E-07 2.93700E-03  X
 2 9.40375E-06 3.10400E-03  X
 2 1.85924E-04 3.59600E-03  X

I need to copy information from the second file into the first file. At the end of each line that lists the nuclide (ex: Ac-223 and Ac-224) is a number (ex: 480 or 682). I need to copy that number from file 2 and insert it into file 1 after the 4th column (1, 482, 1165, etc) in it's own separate column. I need to do that for each line in file 1.

Additionally, I have a third file that I need to extract information from and place in file 1. Here is an example of file 3:

Ac-226        112
0.00000 1.486E+00
0.00010 1.486E+00
0.00014 1.486E+00
0.00015 1.486E+00
0.00016 1.486E+00
0.00018 1.486E+00
0.00020 1.486E+00
          [.....]
Ac-227         73
0.00000 7.974E+01
0.00010 7.925E+01
0.00011 7.921E+01
0.00012 7.916E+01
0.00013 7.911E+01

I need to copy the number at the end of the line with the nuclide in it and paste it after the 5th column in the index file (0, 0, 0, 1). But this is only pasted in if there is 'B-' in the third column, otherwise I need it to list 0.

So, here's an example of what I would want it to look like, I have bolded the added information:

Ac-223     2.10m A             1    480      0      0      0     0 Fr-219    358 9.9000E-01             0        0.0             0        0.0             0        0.0 6.6720 0.02536 0.01903   7 118   0  297  29 223.019136 3.739E-183.739E-18
Ac-224     2.78h ECA         482    682      0      0      0     0 Ra-224    820 9.0900E-01 Fr-220    359 9.1000E-02             0        0.0             0        0.0 0.5662 0.04901 0.23248  15 211   0  398  29 224.021722 2.304E-172.304E-17
Ac-225     10.0d A          1165    778      0      0      0     0 Fr-221    360 1.0000E+00             0        0.0             0        0.0             0        0.0 5.8919 0.02476 0.01708   7 157   0  526  44 225.023229 6.777E-186.777E-18
Ac-226    29.37h B-ECA      1944    260      1    112      0     0 Th-226   1108 8.3000E-01 Ra-226    822 1.7000E-01 Fr-222    361 6.0000E-05             0        0.0 0.0003 0.29143 0.13271  14 140   5   99   1 226.026097 1.048E-171.048E-17

I hope this all makes sense! Thank you so much!

See if this works for you:

#!/usr/bin/ksh
mPTag=""
egrep '^Ac-' mFile2 > mFile2.tag
egrep '^Ac-' mFile3 > mFile3.tag
sort mFile1 mFile2.tag mFile3.tag | while read mTag mFld1 mFld2 mFld3 mFld4 mRest; do
  if [[ "${mTag}" != "${mPTag}" ]]; then
    if [[ "${mPTag}" != "" ]]; then
      mOutLine=${mPTag}' '${mPFld1}' '${mPFld2}' '${mPFld3}' '${mValue2}' '${mPFld4}' '${mValue1}' '${mPRest}
      echo ${mOutLine}
    fi
    mValue1=0
    mValue2=0
  fi
  if [[ "${mFld2}" = "" ]]; then
    mValue1=${mFld1}
  else
    if [[ "${mFld3}" = "" ]]; then
      mValue2=${mFld2}
    else
      mPFld1=${mFld1}
      mPFld2=${mFld2}
      mPFld3=${mFld3}
      mPFld4=${mFld4}
      mPRest=${mRest}
    fi
  fi
  mPTag=${mTag}
done
if [[ "${mPTag}" != "" ]]; then
  mOutLine=${mPTag}' '${mPFld1}' '${mPFld2}' '${mPFld3}' '${mValue2}' '${mPFld4}' '${mValue1}' '${mPRest}
  echo ${mOutLine}
fi