I am trying to generate a tree from a XML file in Bash.
This is a part of the XML file:
<menu name="main_menu" display="Main Menu">
<application name="load_profiles" display="Load Profile"/>
<application name="save_profiles" display="Save Profile"/>
<application name="remove_profiles" display="Delete Profile"/>
</menu>
I have tried to use CAT and GREP and AWK:
cat menu.xml | grep menu\ name | awk -v FS="(display=\"|\" help)" '{print $2}' > menulist.txt
I have first GREPed using the lines that has "Menu Name" and then printed the Tests between 'display="' and '" help' and came out with this output:
Main Menu">
Broadband
Load and Save Profiles
xDSL Interface
But what I want is to Grep all the lines that has "Menu Name", "parameter type", "application name" and "value id" and print their display name in a tree like output. I am not sure how I can Grep multiple values from multiple lines and print specific string from it.
Then I have seen that it is comparatively easier to do this with a XML parser tool. So I have tried with XMLStarlet:
xmlstarlet el menu.xml|awk -F'/' 'BEGIN{print "digraph{"}{print $(NF-1)" -> "$NF}END{print"}"}'> menumenutxt.txt
Using this command I have found the following output:
menu -> menu
menu -> onenter
menu -> menu
menu -> application
menu -> application
menu -> application
menu -> parameter
parameter -> value
parameter -> value
Which definitely looks better and closer to what I want. But it's not printing the display name.
What I am trying to print is something like this:
Main Menu ->
-> Broadband
-> Load and Save Profiles
-> Load Profile
-> Save Profile
-> Delete Profile
Or the following:
Main Menu
-> Broadband
--> Load and Save Profiles
---> Load Profile
---> Save Profile
---> Delete Profile
My aim to to get an output as close to it as possible. Can anyone suggest me how I should proceed with this?