HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Using sed to obtain values of XML tag from several...
Operating System - Linux
1828343
Members
3057
Online
109976
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
04-08-2006 09:57 PM
04-08-2006 09:57 PM
Using sed to obtain values of XML tag from several XML files
HI,
I'm attempting to extract the values of the XML tag from the XML file attached in this posting. The values to be extracted are from the tags, and as shown below:
pmNoOfNonHoReqDeniedCs
pmNoOfNonHoReqDeniedInteractive
pmNoOfNonHoReqDeniedSpeech
I've attempted using "sed" to perform this task on a Linux RH9 machine.
$sed -n 's|\(.*\) |\1|p' sample.xml
pmNoOfNonHoReqDeniedCs
$sed -n 's|\(.*\) |\1|p' sample.xml
pmNoOfNonHoReqDeniedInteractive
$sed -n 's|\(.*\) |\1|p' sample.xml
pmNoOfNonHoReqDeniedSpeech
The "sed" options supplied is able to return the values between the XML tags.
However, I'm unsure how I could loop through the contents of several *.xml files within the same directory and assign the values of, and tags to some variable for display.
Could any help me out?
Thanks
I'm attempting to extract the values of the XML tag from the XML file attached in this posting. The values to be extracted are from the tags
I've attempted using "sed" to perform this task on a Linux RH9 machine.
$sed -n 's|
pmNoOfNonHoReqDeniedCs
$sed -n 's|
pmNoOfNonHoReqDeniedInteractive
$sed -n 's|
pmNoOfNonHoReqDeniedSpeech
The "sed" options supplied is able to return the values between the XML tags.
However, I'm unsure how I could loop through the contents of several *.xml files within the same directory and assign the values of
Could any help me out?
Thanks
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2006 01:52 AM
04-09-2006 01:52 AM
Re: Using sed to obtain values of XML tag from several XML files
You can use the following method:
sed -n 's|<[mtes]*>\(.*\)<[mtes/]*>|\1|p' sample.xml
sed -n 's|<[mtes]*>\(.*\)<[mtes/]*>|\1|p' sample.xml
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2006 11:37 AM
04-09-2006 11:37 AM
Re: Using sed to obtain values of XML tag from several XML files
I'd use:
sed -n 's|<[mes]t>\(.*\)|\1|p' sample.xml
forces the tag matching to be a little more accurate.
But to be truely accurate, you should use backreferencing regular expressions:
sed -n 's|<\([mes]t\)>\(.*\)|\2|p' sample.xml
As for reading these values in, a simple while loop with a read should do, i.e.:
while read LINE
do
echo My value is: $LINE
done < <(sed -n 's|<\([mes]t\)>\(.*\)|\2|p' sample.xml)
(NOTE: This is for a 'bash' shell. For older shells, you'd do 'sed .... | while read LINE' instead)
sed -n 's|<[mes]t>\(.*\)|\1|p' sample.xml
forces the tag matching to be a little more accurate.
But to be truely accurate, you should use backreferencing regular expressions:
sed -n 's|<\([mes]t\)>\(.*\)|\2|p' sample.xml
As for reading these values in, a simple while loop with a read should do, i.e.:
while read LINE
do
echo My value is: $LINE
done < <(sed -n 's|<\([mes]t\)>\(.*\)|\2|p' sample.xml)
(NOTE: This is for a 'bash' shell. For older shells, you'd do 'sed .... | while read LINE' instead)
One long-haired git at your service...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2006 07:28 AM
04-11-2006 07:28 AM
Re: Using sed to obtain values of XML tag from several XML files
Danny,
From various posts you sent in HP-UX and this forums, many of task you are attempting to address using shell would have more simple, reliable and maintenable solutions using PERL scripting instead of shell.
Maybe consider learning this as a long term investment... as becoming efficient with perl is not achieved in one day...
For my own needs, and depending on task and data complexity, I use either SHELL/awk/sed mix or full perl scripts.
Now for the question in this thread, the PERL answer would be to delegate interpretation of your xml input file to XML::Parser and XML::SimpleObject modules.
regards,
antonio.
From various posts you sent in HP-UX and this forums, many of task you are attempting to address using shell would have more simple, reliable and maintenable solutions using PERL scripting instead of shell.
Maybe consider learning this as a long term investment... as becoming efficient with perl is not achieved in one day...
For my own needs, and depending on task and data complexity, I use either SHELL/awk/sed mix or full perl scripts.
Now for the question in this thread, the PERL answer would be to delegate interpretation of your xml input file to XML::Parser and XML::SimpleObject modules.
regards,
antonio.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP