Match from one pattern to second occurrence of second pattern
Given an XML file that contains (NOT "consists of"):
I want to isolate and operate on the lines between <key>system.burn</key> and the second occurrence of <dict>, so:
Now, sed -n '/<key>system.burn<\/key>/,/<dict>/2 p' /etc/authorization would get me what I want... except I'm on a Mac, and so do not have GNU see. That gets me "invalid command code 2" I can delete the 2 and wind up with a valid pattern, but it only returns:
I don't want to just return the six lines after <key>system.burn</key> as I cannot be positive that there will always just be six lines.
I have a feeling awk is going to be the answer here, but I've got a long curve to climb with awk. I'm proud of myself for being able to print $2 or even $NF, so that tells you how advanced I am there :-P
I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'.
Here's a portion of the text I'm trying to parse:
lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb
registrations:
key 4156 4353 0000 0000
... (3 Replies)
Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match.
I'm stuck in an AWK... (9 Replies)
Hello Guyz
I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline
ABC
DEF
LMN
EFG
HIJ
LMN
OPQ
In the above text i need to... (8 Replies)
Hi,
I am getting crazy after days on looking at it:
Bash in Ubuntu 12.04.1
I want to do this:
pattern="system /path1/file1 file1"
new_pattern=" data /path2/file2 file2"
file to edit: data.db
- I need to search in the file data.db for the nth occurrence of pattern
- pattern must... (14 Replies)
Hi experts , im new to Unix,AWK ,and im just not able to get this right.
I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Ive used this snippet of code on a solaris box thousands of times.
But it isnt working on the new linux box
sed -n '/interface LoopBack0/{N;/ ip address /p;}' *.conf
its driving me nuts !!
Is there something Im missing ? (7 Replies)
Im using the command below , but thats not the output that i want. it only prints the odd and even numbers.
awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}'
Im hoping for something like this
file1:
Text hi this is just a test
text1 text2 text3 text4 text5 text6
Text hi... (2 Replies)
Hello Experts , require help . See below output:
File inputs
------------------------------------------
Server Host = mike
id rl images allocated last updated density
vimages expiration last read <------- STATUS ------->... (4 Replies)
AWK command to get file content until 3 occurrence of pattern match,
INPUT FILE:
JMS_BODY_FIELD:JMSText = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<custOptIn xmlns="http://com/walm/ta/cu/ccs/xml2">
<person>Romi</person>
<appName>SAP</appName>
</custOptIn>
... (4 Replies)
Discussion started by: prince1987
4 Replies
LEARN ABOUT CENTOS
xml::libxml::pattern
XML::LibXML::Pattern(3) User Contributed Perl Documentation XML::LibXML::Pattern(3)NAME
XML::LibXML::Pattern - XML::LibXML::Pattern - interface to libxml2 XPath patterns
SYNOPSIS
use XML::LibXML;
my $pattern = XML::LibXML::Pattern->new('/x:html/x:body//x:div', { 'x' => 'http://www.w3.org/1999/xhtml' });
# test a match on an XML::LibXML::Node $node
if ($pattern->matchesNode($node)) { ... }
# or on an XML::LibXML::Reader
if ($reader->matchesPattern($pattern)) { ... }
# or skip reading all nodes that do not match
print $reader->nodePath while $reader->nextPatternMatch($pattern);
$pattern = XML::LibXML::Pattern->new( pattern, { prefix => namespace_URI, ... } );
$bool = $pattern->matchesNode($node);
DESCRIPTION
This is a perl interface to libxml2's pattern matching support http://xmlsoft.org/html/libxml-pattern.html. This feature requires recent
versions of libxml2.
Patterns are a small subset of XPath language, which is limited to (disjunctions of) location paths involving the child and descendant axes
in abbreviated form as described by the extended BNF given below:
Selector ::= Path ( '|' Path )*
Path ::= ('.//' | '//' | '/' )? Step ( '/' Step )*
Step ::= '.' | NameTest
NameTest ::= QName | '*' | NCName ':' '*'
For readability, whitespace may be used in selector XPath expressions even though not explicitly allowed by the grammar: whitespace may be
freely added within patterns before or after any token, where
token ::= '.' | '/' | '//' | '|' | NameTest
Note that no predicates or attribute tests are allowed.
Patterns are particularly useful for stream parsing provided via the "XML::LibXML::Reader" interface.
new()
$pattern = XML::LibXML::Pattern->new( pattern, { prefix => namespace_URI, ... } );
The constructor of a pattern takes a pattern expression (as described by the BNF grammar above) and an optional HASH reference mapping
prefixes to namespace URIs. The method returns a compiled pattern object.
Note that if the document has a default namespace, it must still be given an prefix in order to be matched (as demanded by the XPath
1.0 specification). For example, to match an element "<a xmlns="http://foo.bar"</a>", one should use a pattern like this:
$pattern = XML::LibXML::Pattern->new( 'foo:a', { foo => 'http://foo.bar' });
matchesNode($node)
$bool = $pattern->matchesNode($node);
Given an XML::LibXML::Node object, returns a true value if the node is matched by the compiled pattern expression.
SEE ALSO
XML::LibXML::Reader for other methods involving compiled patterns.
AUTHORS
Matt Sergeant, Christian Glahn, Petr Pajas
VERSION
2.0018
COPYRIGHT
2001-2007, AxKit.com Ltd.
2002-2006, Christian Glahn.
2006-2009, Petr Pajas.
perl v5.16.3 2013-05-13 XML::LibXML::Pattern(3)