bash - grep a specific line, print upper lines to a specific word and/or below lines to a specific word -
I have recently been running on an issue where I can not find a consistent solution.
Let's say we have some XML files and it's been made like the following:
... And let's suppose that & lt; E-mail & gt; and some other stuff can be more options like this, then it can actually be different in length. Now we know "some" that this is "whatever" and grep for it but we do not want that result, we can get the & lt; tenant & gt; and & lt; / Tenant & gt; for all results, including & lt; something & gt; Whatever & lt; / Some & gt; . Since the number of lines & lt; Tenant & gt; and & lt; / Tenant & gt; , so I can not use the -A, -B or -C on grep and any help information can be found here. I currently just make that big, so I have at least all Infos, but maybe once the length is long and my method will get worse.
'/ & lt; Some & gt; Whatever & lt; \ / Something & gt; / {Print $ 0 RT} 'file & lt; Tenant & gt; & Lt; Name & gt; bla & lt; / Name & gt; & Lt; ID & gt; 1 & lt; / Id & gt; & Lt; Some & gt; Whatever & lt; / Some & gt; & Lt; / Tenant & gt; & Lt; Tenant & gt; & Lt; Name & gt; foo & lt; / Name & gt; & Lt; ID & gt; 55 & lt; / Id & gt; & Lt; Some & gt; Whatever & lt; / Some & gt; & Lt; / Tenant & gt;
Comments
Post a Comment