Let's start by writing a script that does what I think I understand you want and then you can tell us what it needs to do differently/additionally:
$ cat tst.awk
BEGIN { FS=";"; print "<rows>
" }
NR==1 { for (i=1; i<=NF; i++) f[$i]=i; next }
{ tag = $(f["id_client"]); gsub(/[0-9]/,"",tag) }
tag == "C" { type="client"; flds="num_tel num_comd" }
tag == "D" { type="pro"; flds="id_client num_fixe" }
{
split("name "flds,n,/ /)
printf "<%s: %s>
", tag, $(f["id_client"])
printf " <%s>
", type
print " <identity>"
for (i=1;i in n;i++)
printf " <%s>%s</%s>
", n[i], $(f[n[i]]), n[i]
print " </identity>"
printf " <locomotion>%s</locomotion>
", locomotion
printf " </%s>
", type
printf "</%s>
", tag
}
END { print "</rows>" }
.
$ awk -v locomotion='car' -f tst.awk file
<rows>
<C: 50C>
<client>
<identity>
<name>gwenael</name>
<num_tel>0998452223</num_tel>
<num_comd>12345</num_comd>
</identity>
<locomotion>car</locomotion>
</client>
</C>
<C: 31C>
<client>
<identity>
<name>marcel</name>
<num_tel>0966442312</num_tel>
<num_comd>654321</num_comd>
</identity>
<locomotion>car</locomotion>
</client>
</C>
<D: 23D>
<pro>
<identity>
<name>judith</name>
<id_client>23D</id_client>
<num_fixe>1045227937</num_fixe>
</identity>
<locomotion>car</locomotion>
</pro>
</D>
</rows>
Now - what else does it need to do?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…