Maybe someone has a better idea, but this should get you started
Code:
#!/usr/bin/sh
infile=$1
outfile=$2
>$outfile # truncate out file
cat $infile | while read line
do
rectype=`echo $line | cut -c 1-2`
if [ "$rectype" = "01" ]
then
contrycode=`echo $line | cut -c 3-4`
# and other fields
cat <<EOF >>$outfile
<header>
<headid>$rectype</headid>
<contry>$contrycode</country>
# and other fields
</header>
EOF
fi
#if [ "$rectype" = "10" ]
#...
done