Code:
BEGIN { print "name1,name2,name3,name4,Title,designation,nationality,dob,national identication,address,listed On,Other information";Title=""; dob=""; nationality="";
}
/*Name(:?)/ {
if (Title != "" )
{
printf ",%s",Title;
Title=" ";
}
if (designation != "" )
{
printf ",%s",designation;
designation=" ";
}
if (nationality != "" )
{
printf ",%s",nationality;
nationality=" ";
}
if (dob != "" )
{
printf ",%s\n",dob;
dob=" ";
}
line = $0;
gsub(/[[:digit:]]+:/,"",line);
gsub(/[[:digit:]]+\./,"",line);
sub(/*Name:/,"",line);
sub(/*Name/,"",line);
split(line,names);
x = 1;
while (x<=3)
{
printf "%s,", names[x];
x++;
}
printf "%s", names[x];
name1 = $4;
name2 = $6;
name3=$8;
name4=$10;
}
##--> Add title field
/Title:/ {
line=$0;
idx1 = index(line,"Title:");
idx2 = index(line,"Designation:");
if (idx2==0)
{
idx2 = length(line)+1;
}
Title = substr(line, idx1+length("Title:"), idx2 - idx1 - length("Title:") );
sub(",",";",Title)
}
##--> Add Designation
/Designation:/ {
line=$0;
idx1 = index(line,"Designation:");
idx2 = index(line,"DOB:");
if (idx2==0)
{
idx2 = length(line)+1;
}
designation = substr(line, idx1+length("Designation:"), idx2 - idx1 - length("Designation:") );
sub(",",";",designation)
}
/*Nationality: / {
line = $0;
idx1 = index(line,"*Nationality: ");
idx2 = index(line,"Passport");
nationality = substr(line, idx1+length("*Nationality: "), idx2 - idx1 - length("*Nationality: ") );
sub(",",";",nationality)
}
/DOB:/ {
line=$0;
idx1 = index(line,"DOB:");
idx2 = index(line,"POB");
if (idx2==0)
{
idx2 = length(line)+1;
}
dob = substr(line, idx1+length("DOB:"), idx2 - idx1 - length("DOB:") );
sub(",",";",dob)
}
##/National identification no.:/ {
##line=$0;
##idx1 = index(line,"National identification no.:");
##idx2 = index(line,"Address");
##if (idx2==0)
##{
## idx2 = length(line)+1;
##}
##dob = substr(line, idx1+length("National identification no.:"), idx2 - idx1 - length("National identification no.:") );
##sub(",",";",National identification no)
##}
##/Title:/ {context="title"; printf "%s:",context}