The task:
I'm trying to get the attribute-value from xml tags with a shell script, split the value up and save them in a .csv-file.
This is how the xml looks like:
<host>
<servers>
<server name="Type1Name1-Port1" >...</server>
<server name="Type2Name2-Port2" >...</server>
<server name="Type3Name3-Port3" >...</server>
...
<server name="TypexNamex-Portx" >...</server>
</servers>
</host>
I'd like to get the values from the "name"-attribute and split them up like following:
Type;Name;Port
The output csv file I want should look like this:
Type1;Name1;Port1
Type2;Name2;Port2
Type3;Name3;Port3
...
Typex;Namex;Portx
The problem:
- I can't install anything on the server
- I can only use "ksh-awk" / "xmllint wihtout --xpath" / "standard linux commands"
I can use any shell-language I want to. I prefer bash and ksh.
My questions:
- Do you think it is possible to solve my task?
- What is the best approach for the sub-tasks? (reading, splitting, writing)
EDIT:
Example data of a server-name:
T-TTT_AAA-A-SSS-PPPP
Where T represents the Type, A the Applicationname, S the Server-Name, P the Port. The length of T, A and S are variable. P is constant.
xmllint --shellandawkorsed. What is the separator between yourType1andName1? Capitalization ?T-TTT_AAA-A-SSS-PPPP, the output should beT-TTT;AAA-A-SSS;PPPP, right ?