Adding new fields to an existing layout

Hi Everybody,
I have an layout file like below

f1 1 char 10,
f2 11 char 2,
f3 13 char 1,
lineend 14 char 1

Their I need to add a new field which would be like

f5 char 3,
f6 char 2

The o/p should be

f1 1 char 10,
f2 11 char 2,
f3 13 char 1,
f5 14 char 3,
f6 17 char 2
lineend 14 char 1 /* Note this should be the last field. */

Now my requirement is , I need to automate this process.
i.e the new field addtion f5 and f6 should be automated and the field name data type and the length will be given in a text file. We need to read that file and modify the layout. Can anyone help me how to approach this?

Note : For the new fields to be added, the spaces in between fields should be similar to the old fields.

Hi Manii,

a.txt is your existing file...

b.txt is file whith new data

cnt=`wc -l a.txt | awk '{print $1}'`
num=`expr $cnt - 1 | bc`
head -$num a.txt >> new.txt
cat b.txt >> new.txt
tail -1 a.txt >> new.txt

Here is code :

#! /bin/ksh

aa=" "
cnt=`wc -l a.txt | awk '{print $1}'`
num=`expr $cnt - 1 | bc`
head -$num a.txt >> new.txt
let i=1

let sec=`tail -1 new.txt | awk '{print $2}'`
las=`tail -1 new.txt | awk '{print $4}'`
let llas=`echo $las | awk -F, '{print $1}'`


bcnt=`wc -l b.txt | awk '{print $1}'`

while [ $i -le $bcnt ]
do
	col1=`head -$i b.txt| tail -1 | awk '{print $1}'`
	col2=`expr $sec + $llas | bc`
	col3=`head -$i b.txt | tail -1 | awk '{print $2}'`
	col4=`head -$i b.txt | tail -1 | awk '{print $3}'`
	echo "${col1}${aa}${col2}${aa}${col3}${aa}${col4}" >> new.txt
	let i=`expr $i + 1 | bc`
	let sec=$col2
	let llas=`echo $col4 | awk -F, '{print $1}'`
	
done
tail -1 a.txt >> new.txt