Hi everyone,
Please help on this:
I have file1:
<file title="Title 1 and 2">
<report>
<title>Title 1</title>
<number>No. 1234</number>
<address>Address 1</address>
<date>October 07, 2009</date>
<description>Some text</description>
</report>
<report>
<title>Title 2</title>
<number>No. 457</number>
<address>Address 2</address>
<date>October 15, 2009</date>
<description>Some text</description>
</report>
</file>
and file2:
<file title="Title 1 and 2">
<report id="No. 1234">
<f v="1">Report x</f>
<f v="1">Report t</f>
<f v="1">Report y</f>
<f v="1">Report u</f>
<f v="1">Report o</f>
<j v="0">Report m</f>
</report>
<report id="No. 457">
<f v="1">Report x</f>
<f v="1">Report t</f>
<f v="1">Report y</f>
<f v="1">Report u</f>
<f v="1">Report o</f>
<j v="0">Report m</f>
</report>
</file>
and I want to get this output:
<si><t>Report</t></si>
<si><t>Tittle</t></si>
<si><t>Number</t></si>
<si><t>Address</t></si>
<si><t>Date</t></si>
<si><t>Description</t></si>
<si><t>Title 1 and 2</t></si>
<si><t>Title 1</t></si>
<si><t>No. 1234</t></si>
<si><t>Address 1</t></si>
<si><t>October 07, 2009</t></si>
<si><t>Some text</t></si>
<si><t>Title 2</t></si>
<si><t>No. 457</t></si>
<si><t>Address 2</t></si>
<si><t>October 15, 2009</t></si>
<si><t>Some text</t></si>
<si><t>Report o</t></si>
<si><t>Report t</t></si>
<si><t>Report u</t></si>
<si><t>Report x</t></si>
<si><t>Report y</t></si>
The things is I'm trying since a couple of hours ago changing my code (below code) to get the output desired,
but the central part (values from file1 in red) that supposed to be as the values in blue above are not being shown correctly, the output I'm getting is.
<si><t>Report</t></si>
<si><t>Tittle</t></si>
<si><t>Number</t></si>
<si><t>Address</t></si>
<si><t>Date</t></si>
<si><t>Description</t></si>
<si><t>Title 1 and 2</t></si>
<si><t></t></si>
<si><t></t></si>
<si><t></t></si>
<si><t></t></si>
<si><t>Title 1</t></si>
<si><t></t></si>
<si><t>No. 1234</t></si>
<si><t></t></si>
<si><t>Address 1</t></si>
<si><t></t></si>
<si><t>October 07, 2009</t></si>
<si><t></t></si>
<si><t>Some text</t></si>
<si><t></t></si>
<si><t></t></si>
<si><t></t></si>
<si><t></t></si>
<si><t></t></si>
<si><t>Title 2</t></si>
<si><t></t></si>
<si><t>No. 457</t></si>
<si><t></t></si>
<si><t>Address 2</t></si>
<si><t></t></si>
<si><t>October 15, 2009</t></si>
<si><t></t></si>
<si><t>Some text</t></si>
<si><t></t></si>
<si><t></t></si>
<si><t></t></si>
<si><t></t></si>
<si><t>Report o</t></si>
<si><t>Report t</t></si>
<si><t>Report u</t></si>
<si><t>Report x</t></si>
<si><t>Report y</t></si>
My code so far is:
awk -F'[<>]' 'BEGIN{F="\t<si><t>";B="</t></si>"
print F"Report"B"\n",F"Tittle"B"\n",F"Number"B"\n",F"Address"B"\n",F"Date"B"\n",F"Description"B}
NR==FNR{
{$2~"file title"; split ($0,N,"\""); print F N[2] B}
{$2=="title" || $2=="number" || $2=="address" || $2=="date" || $2=="description"; print F $3 B}
next}
$2 ~ /f v=\"/{u[$3]}
END{for (i in u) print F i B | "sort"}' file1 file2
May somebody help to show me where is the problem with my code or fix it please?
Thanks in advance