Grepping XML

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Grepping XML

Ron Johnson
Since the gramps backup format is xml, grepping xml can sometimes be useful.  This SE answer should be useful.

https://unix.stackexchange.com/a/405984/39069

If this is part of a well formed XML document you can extract the required part with an XML parser.

To satisfy the well formed requirement, I've wrapped your XML fragment with <root> and </root>.

xmlstarlet sel -t -c '//A[name="Word1"]' -n file.xml

If you cannot satisfy this directly, you can wrap it explicitly

( echo '<root>'; cat file.xml; echo '</root>' ) | xmlstarlet sel -t -c '//A[name="Word1"]' -n

In either case, the output is this:

<A>
<number>100</number>
<name>Word1</name>
</A>


-- 
World Peace Through Nuclear Pacification

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gramps-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-users
https://gramps-project.org