I have simplified my question.
I have a text file with data as below
package1| class1 | test case1 | Pass | endpoint | ref no |
package1| class1 | test case2 | Pass | endpoint | ref no |
package2| class2 | test case1 | Fail | endpoint | ref no | fail reason
package3| class3 | test case2 | | | |
I want to create an xml from the above while will be like as below. logic whenever the field1 differs from previous line field1 create a node and tests cases under it. if field 4 is null then the test is counted as error.I want to keep count of no of test cases no of error and no of failure at package level ie node. and also keep count of test cases , no of error and no of failure at each node
<?xml version="1.0" encoding="UTF-8"?>
<testsuites errors="1" failures="1" tests="4">
<testsuite name="package1" errors="0" failures="0" tests="2">
<Testcase>
<class>class1</class>
<name>Testcase1</name>
<Result>Pass</Result>
<FailReason></FailReason>
</testcase>
<Testcase>
<class>class2</class>
<name>Testcase2</name>
<Result>Pass</Result>
<FailReason></FailReason>
</testcase>
</TestSuite>
<testsuite name="package2" errors="0" failures="1" tests="1">
<Testcase>
<class>class1</class>
<name>Testcase1</name>
<Result>Fail</Result>
<FailReason>FailReason</FailReason>
</testcase>
</TestSuite>
<testsuite name="package3" errors="1" failures="0" tests="1">
<Testcase>
<class>class1</class>
<name>Testcase1</name>
<Result>Fail</Result>
<FailReason>Error</FailReason>
</testcase>
</TestSuite>
</Testsuites>
`
I was using awk to create tried so many code nothing sucessful , i am not sure which code should i put here which i tried almost 6 hours working on it not able to figure out how to do it and dry now. any help is appreciated. any script solution is good not only awk.