There is an issue with the output XML format due to Record separator (RS = "\n \n"). The group of data is separated by an empty line. Any suggestion would be very much helpful to obtain the desired output.
Following is my input which is present in input.txt
Alex
Marks300
SubjectScience
Robin
Marks200
SubjectChemistry
I am trying to get an output as below:
<candidate>
<name>Alex</name>
<marks>Marks300</marks>
<subject>SubjectScience</subject>
</candidate>
<candidate>
<name>Robin</name>
<marks>Marks200</marks>
<subject>SubjectChemistry</subject>
</candidate>
I am trying to use the following code but it is not working:
awk 'BEGIN{FS = "\\n";RS = "\\n\\n";
print " "}
{ print "<candidate>" }
{ print "<name>"$1"</name>" }
{ print "<marks>"$2"</marks>" }
{ print "<subject>"$3"</subject>" }
{ print "</candidate>" }
{print " " }' input.txt > candiatefinaloutput.xml
With the above code, getting an output as below:
<candidate>
<name>alex<\name>
<marks><\marks>
<subject><\subject>
<name>Marks300<\name>
<marks><\marks>
<subject><\subject>
<name>SubjectScience<\name>
<marks><\marks>
<subject><\subject>
<name>Robin<\name>
<marks><\marks>
<subject><\subject>
and so on.