Maybe someone could help me. I want to transform the structure of a xml file.
I have this input.xml: and the required output should be: As you can see, in input.xml there are 2 blocks of "cases" with names (it could be more than 2 "cases" blocks. e.g 5, 7, 8 etc.).
In both "cases" blocks appear some names repeated (Peter, Ely and Mark appear in both blocks)
Then, in the output the "Row" blocks should be obtained as follow:
Block 1: Variables here are in red:
ExpandedColumnCount = Number of "Cases" blocks + 1 = 2 +1 = 3
ExpandedRowCount = Number of unique names + 1 = 5 + 1 = 6
Block 2 (the first "Row" block): The values in red should be taken from "case id" in "cases" blocks.
Blocks 3,4,5...N ("Row" blocks for each unique name): The values in red are taken from "cases" blocks, but needs to look up unique names and show a unique "Row" block for each name and
all related values for each name within the same "Row" block as shown above.
I really hope you could help me with this. I'm a kind of beginner in this type of scripts.
I read your requirements three times and I still could not figure it out.
Hi, thanks for answer.
Sorry for my explanation. In input file there are repeated names and in the output only appear once with their corresponding values. Maybe you could understand better only seeing how is the input and how is the output.
Quote:
Originally Posted by Shell_Life
You have a large project.
I'm not sure, I've seen several questions of more complex xml transformations here, I hope this is not too complex. Maybe awk, sed or combination of those with bash.
Quote:
Originally Posted by Shell_Life
Why do you have to write a solution using unix shell script?
Try using a compiled language.
This because is what I could understand and what I thought could be the solution. I really dont know a compiled language to try doing something like this.
I intend to parse the input in that way because the output would be open in MS Excel, but showing in different layout, as I said before, without repeat the names, only show them once and locate within the same block every associated value to each name. One block for each name.
Sorry for my explanation, I hope somebody could get my english explanation.
Thanks in advance.
Regards.
---------- Post updated 10-06-11 at 03:08 AM ---------- Previous update was 10-05-11 at 11:51 AM ----------
Hi again,
Answering my own question to show if anybody is interested in the future.
I had to separate step by step the conversion needed, it's not pure bash. I helped me with individual awk commands to get
each section of the script.
Probably the same script could be obtained in a unique awk program, I'll like to see how to join this code in a single awk program.
If the rules are always same.. and the criteria for pattern matching are unchanged, which means the actual file is same as sample you have posted except the variables.
This is what I have..
Please note I have just tried to achieve your requirement i.e I hadn't thought about tuning and efficiency.
O/P
Please note, this doesn't include one thing..
Putting entry with zero if the name doesn't appear in any row block. but i think you can try that yourself.
Many thanks for reply and give some of your time to share your knowledge to help. Your code works beautifully!
With your code I've learned more than one thing new.
1-) I didnt know that "cat" can be used in that way, it has a name use cat in that way?
2-) The use of "while read" in combination of awk commands to avoid several steps, processing, resources and memory using array variables.
3-) I had forgotten the great features of "sed" to replace directly at the begin or at the end of a string, great.
I only modified the following in your code (the added code in red).
I changed this:
for this:
and this:
for this (to get zeros when there is not a match)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ I think I'll be able to emulate your code to extend it and process other file that I need to, after this input.xml and input1.xml have
been changed in similar way they will be part of an final output.xml like show below: In order to get that, may you help me with suggestions regarding this (assume your code is rutine2 and rutine1 is a code I have
to add to process input1.xml and I have both rutines working already):
A suggestion or idea in how to surround your script with a loop to process all somename_ci.xml in folder with Rutine1 and proccess
somename_vi.xml in folder with Rutine2.
The final code should look like this:
I hope you can give and idea of how to get this last part of my code.
I have xml file like below, i want change the values at default-value place of each argument name using shell script. like
where argument name= protocol and default-value=tcp,
where argument name =port and default-value= 7223,
where argument name = username and default-value=test,
example
... (12 Replies)
hi, i am new to unix and i have a problem.
--------------------------------------------------------------
sebben.xml
<envelope>
<email> sebben@example.com
</email>
</envelope>
script_mail written in the vi editor.
#!/bin/sh
script to change the value in attribute <email>
echo... (3 Replies)
hi Guys,
this is my requirement, there is a huge xml file of this i have to change 3 lines with out opening the file
/users/oracle > cat lnxdb-pts-454.xml|egrep "s_virtual|s_cluster|s_dlsnstatus"
<cluster_port oa_var="s_clusterServicePort">9998</cluster_port>
<host... (2 Replies)
Dear Members,
I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input.
The contents of a single cell of INFO column is like:
Area:app - aam
Clean Up Criteria:... (0 Replies)
Hi,
I am new to UNIX and shell scripting.
I have to create a shell script(ksh) which parses log4j.xml file for a given webservice name and change the corresponding value from INFO to DEBUG or vice-versa.
My log4j.xml looks like:-
<!-- Appender WEBSERVICENAME-->
<appender... (3 Replies)
Hi All,
I am new user of shell scripting has come up with a problem. that I have a directory structure like :
Home
|
|--------A
| |----trunk
| |-------A_0_1/
| |
| |-------A_0_2/
|
|--------B
| ... (6 Replies)
I have an xml file:
<AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Table1>
<Data1 10 </Data1>
<Data2 20 </Data2>
<Data3 40 </Data3>
<Table1>
</AutoData>
and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only.
I tried using sed... (10 Replies)
Before i start doing something, I wanted to know whether the approach to compare XML file with UNIX file system structure. I have a pre-configured file(contains a list of paths to executables) and i need to check against the UNIX directory structure. what are the various approches should i use ? I... (6 Replies)
Hello all
i have some function what looks like this
class.method("servantName").servantMethod(arg1,arg2,arg3)
now i need to convert it to :
class.method("servantName","servantMethod",arg1,arg2,arg3);
is there any wasy way to do that consider that the arg1+2+3 can be also... (1 Reply)