Matching a block of data sed or ksh

I have the need to check content of very many files for a block of text.

I know the data should match for instance/as an example the following

The list of characters
bugs bunny
tom and jerry 
Mighty mouse 
Felix the cat
/

In the first step, I isolated the interesting data by using sed to print everything between "The list of characters" and the "/"

Now I want to match the entire block by using whats shown above to ensure that the isolated block matches exactly line by line.

If the test block shown above, doesn't match the file containing the isolated and interesting data set a flag to no.

If the test block shown above does match the file containing the isolated and interesting data, set a flag to yes.

I would prefer to do this with sed, awk or ksh. The linux box Im working on has limited perl modules loaded.

The only thing I can think of at this point is loop through the files, then grep each file for every line using the known good data set. That will tell me if a particular lines exists, but wont tell me if the entire block is matched exactly.

Thanks

What have you tried?

I could able to assume your request for some extent

file contains special blocks is named special.txt

akshay@Lenovo-E49:~$ cat special.txt
The list of characters
bugs bunny
tom and jerry 
Mighty mouse 
Felix the cat
/

file to be matched is named as file3.txt

</td><td>=</td><td>819BBC99-5A52-CB11-97AC-86FC3869ED64</td></tr></table></td></tr>
 </tbody></table></div>
<div class="indented">
        <div class="indented">
    <table width="100%" class="node" summary="attributes of core">
 <thead><tr><td class="first">id:</td><td class="second"><div class="id">core</div></td></tr></thead>
 <tbody>
The list of characters
bugs bunny
dummy test1
tom and jerry 
Mighty mouse 
Felix the cat
/
<div class="indented">
<table width="100%" class="node" summary="attributes of lenovo-e49">
 <thead><tr><td class="first">id:</td><td class="second"><div class="id">lenovo-e49</div></td></tr></thead>
 <tbody>
    <tr><td class="first">description: </td><td class="second">Notebook</td></tr>
    <tr><td class="first">product: </td><td class="second">34641N3 (LENOVO_MT_3464)</td></tr>
    <tr><td class="first">vendor: </td><td class="second">LENOVO</td></tr>

and assuming that order of line is not important

akshay@Lenovo-E49:~$ awk 'FNR==NR{special[$0]++;c=NR;next}($0 in special){n++}{if(n==c){print "Yes";exit}}END{if(n!=c)print "No"}' special.txt file3.txt
Yes

Otherwise, please post what you have tried so far, sample input and expected output as and when you request forum for solution ..

grep -A5 "The list of char" file | diff - blockfile
echo $?
0
1 Like