- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sorting and formating script - for scripting champ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 08:02 AM
тАО11-20-2001 08:02 AM
I've got an xml file as follows:
With lots of Drink sections.
I'd like to format all this data as follows:
Bar: StagsHead
Drink === i d === i d === i d ===
0-31 --- yes --- no --- yes ---
31-64 --- no --- yes --- yes ---
and this way too:
Drink: Stout
Taps === StagsHead === NagsHead === Chocolate
5 --- 5 --- X --- X
4 --- X --- 4 --- X
3 --- X --- X --- 3
etc..
Complicated.. so where to start.
I'm thinking for a start to have an option to the script -perbar and -perdrink
Anyway,
Interested to see what comes up!
All replies rewarded.
Later,
Bill
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 08:05 AM
тАО11-20-2001 08:05 AM
Re: sorting and formating script - for scripting champions!
It's time to jump on the perl beerwagon:
http://wwwx.netheaven.com/~coopercc/xmlparser/Parser.html
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 08:07 AM
тАО11-20-2001 08:07 AM
Re: sorting and formating script - for scripting champions!
can you give me an example..
I have it installed for what it's worth!
(except for that module..)
Thanks,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 08:27 AM
тАО11-20-2001 08:27 AM
Re: sorting and formating script - for scripting champions!
There are perl modules available on www.cpan.org for parsing XML, so you won't have to re-invent the wheel completely.
Cheers,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 08:35 AM
тАО11-20-2001 08:35 AM
Re: sorting and formating script - for scripting champions!
For a start grep out each section to a file.
ie.
cat file.xml | grep Name > /tmp/bars
cat file.xml | grep Town > /tmp/town
Etc
search and replace (sed) the < with spaces.
Awk out the name field and output to files
one for each bit of data.
Paula
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 09:03 AM
тАО11-20-2001 09:03 AM
Re: sorting and formating script - for scripting champions!
1. Get all the names
grep "
2. Now get each block categorized under this above name.
For i in "the above"
do
sed -n '/'$i'/,/\<\/Bar\>/p' bar > /tmp/name$$
call_another_function on /tmp/name$$
done
3. This another_function will need to filter out drinks like we filtered out Names in the above and gets properties of each drink. It would be cumbersome if we don't use sed and awk's here.Then a simple printf statement would format the results.
You will definitely need a couple of coffees and may be some drinks mentioned in your xml before you can get this working.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 09:52 AM
тАО11-20-2001 09:52 AM
SolutionIf you *have* to use shell then I'd suggest using awk to convert to a halfway house type format of file and then using normal shell tools to do the rest.
You could use awk similar to below to get the fields out:
awk '
/\
{
do {
if ( $0 ~ "
getline;
} while ($0 != "
}' bar.xml
Of course this will fail the xml is like:
dave
dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 12:18 PM
тАО11-20-2001 12:18 PM
Re: sorting and formating script - for scripting champions!
A task for perl + Bundle::XML.
This Bundle downloads a lot of XML modules from CPAN and allows you to manipulate XML data (to be honest, I started writing your script, but timing issues here prevented me from completing...).
To install Bundle::XML
perl -MCPAN -e "install Bundle::XML"
(as root)
Then, man XML::Parser to see an example on how to do it.
Regards,
Paga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 01:34 PM
тАО11-20-2001 01:34 PM
Re: sorting and formating script - for scripting champions!
The programs assumes that the syntax of the xml file is correct and that the tags are all unique.
The data is slurpped into a hash variable and it should be relativelly easy to reformat the data into whatever report you would like..
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2001 01:45 PM
тАО11-20-2001 01:45 PM
Re: sorting and formating script - for scripting champions!
Find attached the corrected program.
-- Rod Hills