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.

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:


World Peace Through Nuclear Pacification

Check out the vibrant tech community on one of the world's most
engaging tech sites,!
Gramps-users mailing list
[hidden email]