extract data from xml- shell script using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract data from xml- shell script using awk
# 1  
Old 07-16-2007
extract data from xml- shell script using awk

Hi,

This is the xml file that i have.

- <front-servlet platform="WAS4.0" request-retriever="SiteMinder-aware" configuration-rescan-interval="60000">
<concurrency-throttle maximum-concurrency="50" redirect-page="/jsp/defaulterror.jsp" />
- <loggers>
<instrumentation class="com.american.util.frontservlet.DefaultInstrumentation" activation-tag="logRequest" enabled="false" />
<page-hit class="com.american.util.eec.adapter.mvc.DefaultPageHitCapture" enabled="false" />
</loggers>
<input-pipeline />
<output-pipeline />
- <request-handlers>
<handler class="com.american.sso.web.requesthandler.LogonHandler" request-name="un_logon" />
<handler class="com.american.sso.web.requesthandler.LogonHandler" request-name="un_logonchpwd" />
<handler class="com.american.sso.web.requesthandler.RequestParserHandler" request-name="auth_reqparser" />
</request-handlers>
<error-page>/jsp/defaulterror.jsp</error-page>
<request-tag>request_type</request-tag>
- <page-map resolution-strategy="strict">
<page name="logon_page" path="/jsp/logon.jsp" type="local" />
<page name="logonchpwd_page" path="/jsp/logonchpwd.jsp" type="local" />
<page name="help_page" path="/jsp/help.jsp" type="local" />
<page name="error_page" path="/jsp/defaulterror.jsp" type="local" />
<page name="requestparser_page" path="/jsp/JSPTest.jsp" type="local" />
</page-map>
</front-servlet>


I need to extract the handler classs name under the request-handler xml tab.
Could anyone help me out with this?

Thanks a lot.
# 2  
Old 07-16-2007
Try this:

Code:
grep '<handler class="' filename |  sed 's!\(<handler class="\)\(.*\)\(" request-name.*\)!\2!

# 3  
Old 07-16-2007
Not working

Hi jacoden,

The code doesnt seem to work...i am not getti9ng any outputSmilie
# 4  
Old 07-16-2007
Quote:
Originally Posted by jacoden
Try this:

Code:
grep '<handler class="' filename |  sed 's!\(<handler class="\)\(.*\)\(" request-name.*\)!\2!

Jacoden,
The code is not workingSmilie
# 5  
Old 07-16-2007
An easy way:
Code:
awk '/handler class/ {gsub(/<handler class=/,"",$0);gsub(/ \/>/,"",$0);print}' file_xml

# 6  
Old 07-16-2007
Code:
#! /opt/third-party/bin/perl

open(FILE, "<", "inputfile") || die "Unable to open file 'inputfile' <$!>\n";

while(<FILE>) {
  last if( /<\/request-handlers>/ );
  if( $set == 1 ) {
    s/^.*class=\"//;
    s/\".*$//;
    print;
  }
  $set = 1 if( /<request-handlers>/ );
}

close(FILE);

exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract XML block when value is matched (Shell script)

Hi everyone, So i'm struggling with an xml (log file) where we get information about some devices, so the logfile is filled with multiple "blocks" like that. Based on the <devId> i want to extract this part of the xml file. If possible I want it to have an script for this, cause we'll use... (5 Replies)
Discussion started by: Pouky
5 Replies

2. Shell Programming and Scripting

Need get data from XML file through shell script..

hi all, here is the sample log file and these errors are repeated in log file.. i need all the repeated time stamp ,severity and message tags needs to print in output file.. through shell script <log-message> <timestamp>2019-03-13T04:52:49.648-05:00</timestamp> <severity>ERROR</severity>... (17 Replies)
Discussion started by: ravi
17 Replies

3. Shell Programming and Scripting

Parse xml in shell script and extract records with specific condition

Hi I have xml file with multiple records and would like to extract records from xml with specific condition if specific tag is present extract entire row otherwise skip . <logentry revision="21510"> <author>mantest</author> <date>2015-02-27</date> <QC_ID>334566</QC_ID>... (12 Replies)
Discussion started by: madankumar.t@hp
12 Replies

4. Shell Programming and Scripting

How to extract data from XML file using shell scripting?

Hi , I have input file as XML. following are input data #complex.xml Code: <?xml version="1.0" encoding="UTF-8"?><TEST_doc xmlns="http://www.w3.org/2001/XMLSchema-instance"> <ENTRY uid="123456"> <protein> <name>PROT001</name> <organism>Human</organism> ... (1 Reply)
Discussion started by: arun_kohan
1 Replies

5. Shell Programming and Scripting

How to extract data from xml file using shell scripting?

Hi evry1, This is my 1st post in this forum.Pls help me I want to extract some data froma xml file which has 2000 lines using shell scripting. Actually my xml file has some "audio and video codes" which i need to arrange in a column wise format after extracting it using shell scripting.I... (4 Replies)
Discussion started by: arun_kohan
4 Replies

6. Shell Programming and Scripting

Shell script to extract data in repeating tags from xml

Hi, I am new to shell scripting. I need to extract data between repeating tags from an xml file and store the data in an array to process it further. <ns1:root xmlns:ns1="http://example.com/config"> <ns1:interface>in1</ns1:interface> <ns1:operation attribute1="true" attribute2="abd"... (2 Replies)
Discussion started by: sailendra
2 Replies

7. Shell Programming and Scripting

Convert XML to Data File in Shell Script

Hi All, I will be getting a huge XML file with a lot of records in it. I need to convert it into multiple data files. SAMPLE XML FILE <ABSProductCatalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <ProductSalesHierachy> - <Portfolios> - <Portfolio productCode="P1"> ... (8 Replies)
Discussion started by: ragha81
8 Replies

8. Shell Programming and Scripting

sed or awk to extract data from Xml file

Hi, I want to get data from Xml file by using sed or awk command. I want to get the following result : mon titre 1;Createur1;Dossier1 mon titre 1;Createur1;Dossier1 and save it in cvs file (fichier.cvs). FROM this Xml file (test.xml): <playlist version="1"> <trackList> <track>... (1 Reply)
Discussion started by: yeclota
1 Replies

9. Shell Programming and Scripting

Perl script for extract data from xml files

Hi All, Prepare a perl script for extracting data from xml file. The xml data look like as AC StartTime="1227858839" ID="88" ETime="1227858837" DSTFlag="false" Type="2" Duration="303" /> <AS StartTime="1227858849" SigPairs="119 40 98 15 100 32 128 18 131 23 70 39 123 20 120 27 100 17 136 12... (3 Replies)
Discussion started by: allways4u21
3 Replies

10. Shell Programming and Scripting

Help with shell script to extract data from XML file

Hello Scripting Gurus, I need help with extracting data from the XML file using shell script. The data is in a large XML and I need to extract the id values of all completedworkflows. Here is a sample of it. Input and output data is also in the attached text files. <wfregistry>... (5 Replies)
Discussion started by: yajaykumar
5 Replies
Login or Register to Ask a Question