Skip to main content
added 30 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the input is a well-formed XML document (like the example in terdon's answer, but not what's shown in the question), you may use xmlstarlet to output a copy of each entry node with a certain name and proteinClass's source attribute.

xmlstarlet select --template \
   --copy-of '//entry[name = "TNMD" and proteinClasses/proteinClass/@source = "MEMSAT3"]' \
   -nl file

This selects all entry nodes with a particular name that also has a proteinClasses/proteinClass sub-node with a particular source attribute value. A copy of each matching entry node will be outputted with a trailing newline added.

Assuming the input is a well-formed XML document (like the example in terdon's answer, but not what's shown in the question), you may use xmlstarlet to output a copy of each entry node with a certain name and proteinClass's source attribute.

xmlstarlet select --template \
   --copy-of '//entry[name = "TNMD" and proteinClasses/proteinClass/@source = "MEMSAT3"]' \
   -nl file

This selects all entry nodes with a particular name that also has a proteinClasses/proteinClass sub-node with a particular source attribute value. A copy of each matching entry node will be outputted.

Assuming the input is a well-formed XML document (like the example in terdon's answer, but not what's shown in the question), you may use xmlstarlet to output a copy of each entry node with a certain name and proteinClass's source attribute.

xmlstarlet select --template \
   --copy-of '//entry[name = "TNMD" and proteinClasses/proteinClass/@source = "MEMSAT3"]' \
   -nl file

This selects all entry nodes with a particular name that also has a proteinClasses/proteinClass sub-node with a particular source attribute value. A copy of each matching entry node will be outputted with a trailing newline added.

added 52 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the input is a well-formed XML document (yourlike the example input is not as it doesin terdon's answer, but not contain a singular root-nodewhat's shown in the question), you may use xmlstarlet to output a copy of each entry node with a certain name and proteinClass's source attribute.

xmlstarlet select --template \
   --copy-of '//entry[name = "TNMD" and proteinClasses/proteinClass/@source = "MEMSAT3"]' \
   -nl file

This selects all entry nodes with a particular name that also has a proteinClasses/proteinClass sub-node with a particular source attribute value. A copy of each matching entry node will be outputted.

Assuming the input is a well-formed XML document (your example input is not as it does not contain a singular root-node), you may use xmlstarlet to output a copy of each entry node with a certain name and proteinClass's source attribute.

xmlstarlet select --template \
   --copy-of '//entry[name = "TNMD" and proteinClasses/proteinClass/@source = "MEMSAT3"]' \
   -nl file

This selects all entry nodes with a particular name that also has a proteinClasses/proteinClass sub-node with a particular source attribute value. A copy of each matching entry node will be outputted.

Assuming the input is a well-formed XML document (like the example in terdon's answer, but not what's shown in the question), you may use xmlstarlet to output a copy of each entry node with a certain name and proteinClass's source attribute.

xmlstarlet select --template \
   --copy-of '//entry[name = "TNMD" and proteinClasses/proteinClass/@source = "MEMSAT3"]' \
   -nl file

This selects all entry nodes with a particular name that also has a proteinClasses/proteinClass sub-node with a particular source attribute value. A copy of each matching entry node will be outputted.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Assuming the input is a well-formed XML document (your example input is not as it does not contain a singular root-node), you may use xmlstarlet to output a copy of each entry node with a certain name and proteinClass's source attribute.

xmlstarlet select --template \
   --copy-of '//entry[name = "TNMD" and proteinClasses/proteinClass/@source = "MEMSAT3"]' \
   -nl file

This selects all entry nodes with a particular name that also has a proteinClasses/proteinClass sub-node with a particular source attribute value. A copy of each matching entry node will be outputted.