There are similar questions but none of them quite address the issue I have.
Simply put, I need to print every block that contains any string I'm looking for. Each block start line contains: <entry version=
For more detail see below:
I want to search a massive file (hundreds of thousands of lines) printing each entire region (block) between patterns if a certain string is identified within the pattern region (block).
I get that I can print entire regions between patterns, where start and end identifiers for these blocks are "/<entry version=" using:
awk '/<entry version=/{flag=1} flag; /<entry version=/{flag=0}'
but how do I get it to only print the entire block if certain strings are found between these patterns?
Shortest part of the real data looks like this for a block region (though in reality each block is thousands of lines long), I want to thank Terdon for sorting a better example for me to use:
<entry version="21.1" url="http://v21.proteinatlas.org/ENSG00000000003">
<name>TSPAN6</name>
<synonym>T245</synonym>
<synonym>TM4SF6</synonym>
<synonym>TSPAN-6</synonym>
<identifier id="ENSG00000000003" db="Ensembl" version="103.38" assembly="GRCh38.p13" gencodeVersion="37">
<xref id="O43657" db="Uniprot/SWISSPROT"/>
<xref id="7105" db="NCBI GeneID"/>
</identifier>
<proteinClasses>
<proteinClass source="MDM" id="Ma" parent_id="" name="Predicted membrane proteins"/>
In the above real format, I would be checking the name and synonyms for specific strings, so if I was looking for "TSPAN6" then this block would be printed. The blocks are thousand of lines each so below is just a made up mini version to explain how I want to print blocks based on string matches within the block.
Here is an example, if my strings were "MEMSAT" and "TNMD"
Example input:
<entry version="21.1" url="http://v21.proteinatlas.org/ENSG00000000003">
<name>TSPAN6</name>
<synonym>T245</synonym>
<synonym>TM4SF6</synonym>
<synonym>TSPAN-6</synonym>
<identifier id="ENSG00000000003" db="Ensembl" version="103.38" assembly="GRCh38.p13" gencodeVersion="37">
<xref id="O43657" db="Uniprot/SWISSPROT"/>
<xref id="7105" db="NCBI GeneID"/>
</identifier>
<proteinClasses>
<proteinClass source="MDM" id="Ma" parent_id="" name="Predicted membrane proteins"/>
<proteinClass source="Ezkurdia et al 2014" id="Eb" parent_id="" name="Protein evidence (Ezkurdia et al 2014)"/>
</proteinClasses>
<proteinEvidence evidence="Evidence at protein level">
<evidence source="HPA" evidence="Evidence at transcript level"/>
<evidence source="MS" evidence="Not available"/>
<evidence source="UniProt" evidence="Evidence at protein level"/>
</proteinEvidence>
</entry>
<entry version="21.1" url="http://v21.proteinatlas.org/ENSG00000000005">
<name>TNMD</name>
<synonym>BRICD4</synonym>
<synonym>ChM1L</synonym>
<synonym>myodulin</synonym>
<synonym>TEM</synonym>
<synonym>tendin</synonym>
<identifier id="ENSG00000000005" db="Ensembl" version="103.38" assembly="GRCh38.p13" gencodeVersion="37">
<xref id="Q9H2S6" db="Uniprot/SWISSPROT"/>
<xref id="64102" db="NCBI GeneID"/>
</identifier>
<proteinClasses>
<proteinClass source="MDM" id="Ma" parent_id="" name="Predicted membrane proteins"/>
<proteinClass source="MDM" id="Md" parent_id="" name="Membrane proteins predicted by MDM"/>
<proteinClass source="MEMSAT3" id="Me" parent_id="" name="MEMSAT3 predicted membrane proteins"/>
</proteinClasses>
<proteinEvidence evidence="Evidence at protein level">
<evidence source="HPA" evidence="Evidence at transcript level"/>
<evidence source="MS" evidence="Not available"/>
<evidence source="UniProt" evidence="Evidence at protein level"/>
</proteinEvidence>
</entry>
Example output:
<entry version="21.1" url="http://v21.proteinatlas.org/ENSG00000000005">
<name>TNMD</name>
<synonym>BRICD4</synonym>
<synonym>ChM1L</synonym>
<synonym>myodulin</synonym>
<synonym>TEM</synonym>
<synonym>tendin</synonym>
<identifier id="ENSG00000000005" db="Ensembl" version="103.38" assembly="GRCh38.p13" gencodeVersion="37">
<xref id="Q9H2S6" db="Uniprot/SWISSPROT"/>
<xref id="64102" db="NCBI GeneID"/>
</identifier>
<proteinClasses>
<proteinClass source="MDM" id="Ma" parent_id="" name="Predicted membrane proteins"/>
<proteinClass source="MDM" id="Md" parent_id="" name="Membrane proteins predicted by MDM"/>
<proteinClass source="MEMSAT3" id="Me" parent_id="" name="MEMSAT3 predicted membrane proteins"/>
</proteinClasses>
<proteinEvidence evidence="Evidence at protein level">
<evidence source="HPA" evidence="Evidence at transcript level"/>
<evidence source="MS" evidence="Not available"/>
<evidence source="UniProt" evidence="Evidence at protein level"/>
</proteinEvidence>
</entry>