Need help to extract the start to end tag of xml code when a pattern is matched. For example, I have this in my xml file:
<entry>
<log_time>20150618-00:06:30</log_time>
<description><![CDATA[Connection established]]></description>
<service>SSH</service>
<sessionid>02881141</sessionid>
<type>0</type> <severity>0</severity>
<lstnconnaddr>10.10.10.100:22</lstnconnaddr>
<cliconnaddr>10.10.11.201:63530</cliconnaddr>
<sguid>04AD6AD5-FB2E-4F03-7993-447648CC3EED</sguid>
</entry>
<entry>
<log_time>20150618-00:06:30</log_time>
<description><![CDATA[Sent server version: SSH-2.0-0]]></description>
<service>SSH</service>
<sessionid>08878297</sessionid>
<type>0</type> <severity>1</severity>
<lstnconnaddr>10.10.10.100:22</lstnconnaddr>
<cliconnaddr>10.10.11.201:63529</cliconnaddr>
<sguid>04AD6AD5-FB2E-4F03-7993-447648CC3EED</sguid>
</entry>
<entry>
<log_time>20150616-00:00:00</log_time>
<description><![CDATA[SSH Transport agreed algorithms
Key exchange algorithm: diffie-hellman-group14-sha1
Server host key algorithm: ssh-rsa
Client encryption algorithm: aes256-ctr
Client MAC algorithm: hmac-sha1
Client compression algorithm: none
Client language:
Server encryption algorithm: aes256-ctr
Server MAC algorithm: hmac-sha1
Server compression algorithm: none
Server language:
]]></description>
<service>SSH</service>
<sessionid>48018549</sessionid>
<type>0</type> <severity>1</severity>
<lstnconnaddr>10.10.10.100:22</lstnconnaddr>
<cliconnaddr>10.10.11.201:60580</cliconnaddr>
<sguid>04AD6AD5-FB2E-4F03-7993-447648CC3EED</sguid>
</entry>
My pattern will be the client IP - 10.10.11.201 in this example.
I have certain IPs to look for in multiple xml files and the tags are not uniform, some have more lines than the others - for this reason, I cannot use "grep" with -B or -A, hence, the basis should be the start-tag <>
to end-tag </>
to get the entire transaction of that IP.
Let me try to better put what I'm looking for. For example, I'm looking for lines with 10.10.11.201:
<cliconnaddr>10.10.11.201:63529</cliconnaddr>
When this is found, I need the entire start-end tag:
<entry>
<log_time>20150618-00:06:30</log_time>
<description><![CDATA[Sent server version: SSH-2.0-0]]></description>
<service>SSH</service>
<sessionid>08878297</sessionid>
<type>0</type> <severity>1</severity>
<lstnconnaddr>10.10.10.100:22</lstnconnaddr>
<cliconnaddr>10.10.11.201:63529</cliconnaddr>
<sguid>04AD6AD5-FB2E-4F03-7993-447648CC3EED</sguid>
</entry>
Preferably using bash, awk, sed, perl.
Thanks!