I have a base file FILE1 with the following data
FILE1.dat
21111111110001343 000001004OLF 029100020091112
21111111110000060 000001004ODL-CH001000020091112
22222222220000780 000001013OLF 006500020091112
23333333330001695 000001039OLF 030600020091112
23333333330000111 000001039ODL-SP002000020091112
23333333330000060 000001039ODL-CH001000020091112
24444444440001416 000001045OLF 011800020091112
......
......
..etc
i want to write a program in .KSH that the FILE2.dat should have only 4 records like below appending two new columns spouse_col & child_col at the end of each line remember this should be in while read line do loop
ODL-Ch = child_col ,
ODL-Sp = spouse_col
FILE2.DAT
spouse_col child_col
21111111110001343 000001004OLF 029100020091112 0000000 0000060
22222222220000780 000001013OLF 006500020091112 0000000 0000000
23333333330001695 000001039OLF 030600020091112 0000111 0000060
24444444440001416 000001045OLF 011800020091112 0000000 0000000
write now i am doing like this but
while read line
do
rec_no=`echo $line|cut -c2-10`
ben_type=`echo $line|cut -c28-33`
amount=`echo $line|cut -c11-18`
if [[ $rec_cnt -eq 1 ]]
then
prior_rec_no=$rec_no
prev_line=$line
else
if [[ $rec_no -eq $prior_rec_no ]]
then
if [[ $ben_type = "ODL-SP" ]]
then
spouse_amt=$amount
prev_line="$prev_line $spouse_amt"
elif [[ $ben_type = "ODL-CH" ]]
then
child_amt=$amount
prev_line="$prev_line $child_amt"
fi
else
echo $prev_line >> FILE2.DAT
prev_line=$line
prior_rec_no=$rec_no
fi
spouse_amt=""
child_amt=""
fi
(( rec_cnt=rec_cnt + 1 ))
prior_rec_no=$rec_no
done <FILE1.DAT
i getting the outfile FILE2.DAT for the above code
spouse_col child_col
21111111110001343 000001004OLFXXX029100020091112 0000060 (this is wrong as this should map to child_column)
22222222220000780 000001013OLFXXX006500020091112
23333333330001695 000001039OLFXXX030600020091112 0000111 0000060
24444444440001416 000001045OLFXXX011800020091112