Matching a block of data sed or ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matching a block of data sed or ksh
# 1  
Old 09-09-2013
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

Code:
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

Last edited by vbe; 09-09-2013 at 08:14 AM.. Reason: code not quote tags...
# 2  
Old 09-09-2013
What have you tried?
# 3  
Old 09-09-2013
I could able to assume your request for some extent

file contains special blocks is named special.txt
Code:
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
Code:
</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

Code:
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 ..

Last edited by Scrutinizer; 09-09-2013 at 10:42 AM.. Reason: Tone
# 4  
Old 09-09-2013
Code:
grep -A5 "The list of char" file | diff - blockfile
echo $?
0

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

IN Between Data after matching the Pattern

HI , I WANT TO RETRIVE IN BETWEEN DATA FROM PARENTHESIS AND I AM GETTING ERRORS WHILE RUN THE AWK.I HAVE 2 FILES AND WANT TO PROCESS 1ST FILE PATTERN TO 2ND FILE AND WRITES INTO OUTPUT FILE.THIS TIME I AM PUTTING WHERE EXACTLY I AM GETTING ERRORS.SO PLEASE HELP. PATTERN_FILE.TXT --------------... (1 Reply)
Discussion started by: andrew_11
1 Replies

2. Shell Programming and Scripting

Need awk/sed command to pull out matching lines from a block

Hi, In order to make our debugging easier in log files, I need this script. My log file will be structured like this : ------Invoking myfile -param:start_time=1371150900000 -param:end_time=1371151800000 for 06/14/2013 <multiple lines here> ..... - Step Sybase CDR Table.0 ended... (3 Replies)
Discussion started by: Lakshmikumari
3 Replies

3. Shell Programming and Scripting

Printing a block of lines from a file, if that block does not contain two patterns using sed

I want to process a file block by block using sed, and if that block does not contain two patterns, then that complete block has to be printed. See below for the example data. ................................server 1............................... running process 1 running... (8 Replies)
Discussion started by: Kesavan
8 Replies

4. Shell Programming and Scripting

Matching the entries and printing data

Hi all, I have a file with Id which I want to compare it with other file to get the sequence of a particular id. File 1 with ID Q7L8J4 Q676U5 Q8NAA4 Q5TYW2 Q5SQ80 Q5VUR7 Q4UJ75 Q96IX9 Q7Z4T9 Q6NTF7 Q8IZP0 Q9NYB9 Q9P2A4 O14639 Q9ULW3 (5 Replies)
Discussion started by: manigrover
5 Replies

5. Shell Programming and Scripting

ksh Multiple Pattern Matching Operators

I figured this would be simple, but I am stuck. Variable longpath="/dir1/dir2/dir3/filename.stuff.morestuff.garbage" I want to end up with just "filename.extra.moreextra". So, I want to get rid of the path and .garbage I want to do this with just ksh internals. So, no sed,grep,awk,expr,... (4 Replies)
Discussion started by: Topaz
4 Replies

6. Shell Programming and Scripting

Compare two files and get matching data

Hi, Can anyone help me to compare two files and get the matching data... say i have file1 and file2 ... file1 has 300 unique data with that i need to match with file2 to see how may are matching.. file2 have 1000 records. (4 Replies)
Discussion started by: zooby
4 Replies

7. AIX

Matching command scroll - ksh

In ksh is there a was to scroll thru all matching commands? For example I executed several commands over several days. Is there a way to scroll thru all the matching 'find' commands only that was executed? No messing with the .history file. Anyway to do this from the command prompt? TIA. (3 Replies)
Discussion started by: Un1xNewb1e
3 Replies

8. Shell Programming and Scripting

Pattern matching in ksh

In the Korn shell is it possible to truncate a pattern like this: - ) ]] So that it is not necessary to enter 8 times? (2 Replies)
Discussion started by: steadyonabix
2 Replies

9. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

10. Shell Programming and Scripting

ksh pattern matching

I try to use the pattern substitution operators as documented in the O'Reilley "Learning the Korn Shell" but it doesn't seem to work as advertised. This works all right: var='Regular expressions rules!' $ echo ${var//e/#} R#gular #xpr#ssions rul#s! The docs says that using !(expr)... (5 Replies)
Discussion started by: ripat
5 Replies
Login or Register to Ask a Question