Sponsored Content
Top Forums Shell Programming and Scripting Need help in creating a Unix Script to parse xml file Post 302184110 by Franklin52 on Thursday 10th of April 2008 01:24:50 PM
Old 04-10-2008
Try this:

Code:
awk 'BEGIN{FS="<|>"}
NF==5&&!f{printf("%s",$3);f=1;next}
NF==5&&f{printf(",%s",$3)}
END{print ""}
' file

Regards

Last edited by Franklin52; 04-10-2008 at 02:39 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

2. Shell Programming and Scripting

Parse XML file

Hi, I need to parse the following XML data enclosed in <a> </a> XML tag using shell script. <X> ..... </X> <a> <b> <c>data1</c> <c>data2</c> </b> <d> <c>data3</c> </d> </a> <XX> ... </XX> (5 Replies)
Discussion started by: viki
5 Replies

3. Shell Programming and Scripting

Parse a string in XML file using shell script

Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it... (46 Replies)
Discussion started by: ayhanne
46 Replies

4. Shell Programming and Scripting

How can I parse xml file?

How can I parse file containing xml ? I am sure that its best to use perl - but my perl is not very good - can someone help? Example below contents of file containing the xml - I basically want to parse the file and have each field contained in a variable.. ie. I want to store the account... (14 Replies)
Discussion started by: frustrated1
14 Replies

5. Shell Programming and Scripting

Need to Parse XML from bash script

I am completely new to bash scripting and now need to write a bash script that would parse a XML file and take out values from specific tags. I tried using xsltproc, xml_grep commands. But the issue is that the XML i am trying to parse is not UTF 8. so those commands are unable to parse my XML's... (4 Replies)
Discussion started by: shivashankar.g
4 Replies

6. Shell Programming and Scripting

Parse XML file in shell script

Hi Everybody, I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example : <section1> <subsection1> X=... Y=... Z=... <\subsection1> <subsection2> X=... Y=... Z=...... (2 Replies)
Discussion started by: yassine
2 Replies

7. Shell Programming and Scripting

parse xml file

Hello all, Given the following extract from a xml file with multiple <JOB> .... </JOB> entries <JOB APPLICATION="APP" APR="0" AUG="0" AUTHOR="AUT" AUTOARCH="0" CMDLINE="/tmp/test1 %%var" CONFIRM="1" CREATION_DATE="20100430" CREATION_TIME="130739" ... (2 Replies)
Discussion started by: cabrao
2 Replies

8. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

9. UNIX for Dummies Questions & Answers

Parse xml file

HI Guys, Input .XML <xn:MeContext id="L0307"> <xn:ManagedElement id="1"> <xn:VsDataContainer id="1"> <xn:attributes> <xn:vsDataType>vsDataENodeBFunction</xn:vsDataType> ... (3 Replies)
Discussion started by: pareshkp
3 Replies

10. Shell Programming and Scripting

Parse xml file

I am trying to create a shell script that will parse an xml file (file attached). awk '/Id v=/ { print }' Test.xml | sed 's!<Id v=\"\(.*\)\"/>!\1!' > output.txt An output.txt file is created but it is empty. It should contain the value 222159 in it. Thanks. (7 Replies)
Discussion started by: cmccabe
7 Replies
Data::Stag::BaseGenerator(3pm)				User Contributed Perl Documentation			    Data::Stag::BaseGenerator(3pm)

NAME
Data::Stag::BaseGenerator - base class for parsers and other event generators SYNOPSIS
# writing the parser package MyParser; use base qw(Data::Stag::BaseGenerator); sub parse_fh { my ($self, $fh) = shift; my $lnum = 0; $self->start_event('data'); while (<$fh>) { ++$lnum; $self->line_no($lnum); # do stuff $self->start_event('foo'); # ... $self->event(blah=>5); # if (/incorrect_line/) { $self->parse_err('line not in correct format'); } # ... $self->end_event('foo'); } $self->pop_stack_to_depth(0); } 1; # using the parser my $p = MyParser->new; my $h = MyHandler->new; # see Data::Stag::BaseHandler my $eh = Data::Stag->makehandler; $p->handler($h); $p->errhandler($eh); $p->parse($file); # result tree print $h->stag->xml; # write parse errs on standard err printf *STDERR $p->errhandler->stag->xml; # using the parser from the command line unix> stag-parse.pl -p MyParser -w xml -e err.xml > out.xml # using the parser from the command line via intermediate handler unix> stag-handle.pl -p MyParser -m MyHandler -w xml -e err.xml > out.xml DESCRIPTION
This is the base class for all parsers and event generators parsers/generators take some input (usually a filehandle, but a generator could be a socket listener, for example) and fire stag events stag events are start_event NODENAME evbody DATA end_event NODENAME {optional} event NODENAME DATA These events can be nested/hierarchical If uncaught, these events are stacked into a stag tree, which can be written as xml or one of the other stag formats specialised handlers can be written to catch the events your parser throws For example, you may wish to write a pod parser that generates nested events like this: <pod> <section> <type>head1</type> <name>NAME</name> <text>Data::Stag - Structured Tags datastructures</text> </section> ... </pod> (see the source for Data::Stag::PodParser for details) You can write handlers that take the pod-xml and generate something - for example HTML parsers may encounter unexpected things along the way - they may throw an exception, and fall over - or they may choose to fire an error event. by default, error event streams are diverted to STDERR. You can create your own error handlers PUBLIC METHODS
new Title: new Args: Return: L<Data::Stag::BaseGenerator> Example: CONSTRUCTOR handler Title: handler Function: GET/SET ACCESSOR METHOD Args: handler L<Data::Stag::BaseHandler> optional Return: L<Data::Stag::BaseHandler> Example: $p->handler(MyHandler->new); each parser has a handler - all events generated are passed onto the handler; the default handler simply sits there collecting events errhandler Title: errhandler Function: GET/SET ACCESSOR METHOD Args: handler L<Data::Stag::BaseHandler> optional Return: L<Data::Stag::BaseHandler> Example: $p->errhandler(Data::Stag->makehandler); each parser has an error handler - if the parser encounters things it does not expect, it can pass errors to the errorhandler if no errorhandler is set, an XML event handler that writes to STDERR is used cache_errors Title: cache_errors Args: Return: Example: $p->cache_errors If this is called, all errors will be cached rather than written to STDERR The error list can be accessed like this $p->parse($fn); @errs = $p->errhandler->stag->get_error; parse Example - $parser->parse($file1, $file2); Returns - Args - filenames str-LIST parses a file parse Example - $parser->parse_fh($fh) Returns - Args - fh FILEHANDLE parses an open filehandle PROTECTED METHODS
These methods are only of interest if you are making your own parser/generator class start_event NODENAME evbody DATA end_event NODENAME {optional} event NODENAME DATA SEE ALSO
Data::Stag Data::Stag::BaseHandler perl v5.10.0 2008-06-03 Data::Stag::BaseGenerator(3pm)
All times are GMT -4. The time now is 06:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy