08-26-2011
line-basedtools like awk, sed, shells, aren't very good at handling xml because they're not recursive parsers. (Well, it parses THEIR language recursively, but doesn't parse text they read in recursively -- things like yacc do..) Usually you'd use a language like perl or python and load an xml module. Could you tell us what your actual goal is instead of the way you want to do it?
Last edited by Corona688; 08-26-2011 at 02:41 AM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi people!,
I need extract from the file (test-file.txt) the values between
<context> and </context> tag's , the total are 7 lines,but i can only get 5 or 2 lines!!:confused:
Please look my code:
#awk '/context/{flag=1} /\/context/{flag=0} !/context/{ if (flag==1) p
rint $0; }'... (3 Replies)
Discussion started by: ricgamch
3 Replies
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
Hello everyone,
Firstly i do not require alot of help.. i am right at the end of finishing my scipt but cannot find a solution to the last part.
What i need to do is, prompt the user for a file to work with, which i have done.
promt the user for an output file - which is done.
#!/bin/bash... (14 Replies)
Discussion started by: hugh86
14 Replies
5. Shell Programming and Scripting
Hello,
I have two text files (txt1 and txt2). txt1 contains many lines with a single number in each line. txt2 (xml format) contains information about the numbers given in txt1. I need to insert one line in txt2 within the scope of each number taken from txt1.
Sample problem:
txt1:
12
23... (1 Reply)
Discussion started by: shekhar2010us
1 Replies
6. UNIX for Dummies Questions & Answers
Hi Guys,
Can you help me in creating shell script using sed,awk etc commands to generate csv file using xml file. (5 Replies)
Discussion started by: sbk
5 Replies
7. Shell Programming and Scripting
Ok, so I have a bash script with an embedded expect statement.
Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time.
Here's my command:
cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv
Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies
8. Shell Programming and Scripting
trying to write up a script to put the suffix back.
heres what I have but can't get it to do anything :(
would like it to be name.date.suffix
rsync -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~" --bwlimit=1024 /mymounts/test1/ /mymounts/test2/
while IFS=. read -r -u 9 -d '' name... (1 Reply)
Discussion started by: jmituzas
1 Replies
9. Shell Programming and Scripting
Hi All,
I want to modify(changing the status from "on" to "off" status of Stage-element value from the below xml file using sed or awk:
File Name: global.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<widget>
<name>HTTP-POOL</name>
<attributes>
... (5 Replies)
Discussion started by: wamqemail2
5 Replies
10. Shell Programming and Scripting
Guys, I have a variable in a script that I want to transform to into something else Im hoping you guys can help. It doesn't have to use sed/awk but I figured these would be the simplest.
DATE=20160120
I'd like to transform $DATE into "01-20-16" and move it into a new variable called... (8 Replies)
Discussion started by: dendenyc
8 Replies
LEARN ABOUT DEBIAN
data::stag::basegenerator
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)