String compare in multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String compare in multiple files
# 1  
Old 11-12-2009
String compare in multiple files

Hi

I have a requirement to process number of files matching a criteria. The resulted file would be processed indivdually looking for a particular string until another one found lines afterwards. Then look for the occurrence of another string in the result count and display/return the result.

Continue the process till the EOF reached then to take the next file do the same ... till no more files to process

example :

File1.log

######### AUD57#########
<:_:REQUESTSTRUCTURE>
<MESSAGE>.........
.............
.........
........
</ITEM>
.........
........
</ITEM>
.........
........
</ITEM>
.........
........
</ITEM>
</MESSAGE>
</:_:REQUESTSTRUCTURE>
................
.............
..............
..............

######### AUD57#########
<:_:REQUESTSTRUCTURE>
<MESSAGE>.........
.............
.........
........
</ITEM>
.........
........
</ITEM>
.........
........
</ITEM>
.........
........
</ITEM>
</MESSAGE>
</:_:REQUESTSTRUCTURE>
...........
EOF

So all I wanted to know is how many occaurcnce of </item> in this log file after "######### AUD57#########" and between "</:_:REQUESTSTRUCTURE>"

I have a kind of script which does this but takes ages to result (with process line by line). so would like to see a simpler and much faster solution - HELP please URGENT

cheers
Arun
# 2  
Old 11-12-2009
Is this what you are looking for?

Code:
nawk '
        /######### AUD57#########/{a++}
        /<\/ITEM>/{items[a]++}
        END{
                for( i in items ){
                        print "No of items in AUD57("i") is - "items[i]
                        t += items[i]
                }
                print "Total items in file = "t
        }
' infile

# 3  
Old 11-13-2009
It does it almost but the problem i have is slightly different..

I need to find ITEMS between ##### AUD57##
and
</:_:REQUESTSTRUCTURE>

The reason for that is there are other ITEMS in the log which I am not intrested at all (between AUD57 till another AUD57).

Find how many items for AUD57 till the </:_:REQUESTSTRUCTURE>.

hope that makes little more clear.

But,
Thanks a lot for the response and much appreciated. Great and hope to see a response soon.

cheers
arun
# 4  
Old 11-13-2009
Try this:

Code:
awk '
/AUD57/{f=1} 
/<\/ITEM>/ && f {c++}
/<\/:_:REQUESTSTRUCTURE>/{print "Number of occurrence: "c; exit}
' file


Last edited by Franklin52; 11-13-2009 at 07:57 AM.. Reason: Adding "&& f"
# 5  
Old 11-13-2009
Tried it but giving wrong results. I have got the test log file ... and i would expect 9 ITEMS between "...AUD57..." till </_:RequestStructure>.

Code:
#####====> AUD57 - ACTION
<_:RequestStructure>
        </item>
        </item>
        </item>
</_:RequestStructure>

</item>

#####====> AUD57 - ACTION
<_:RequestStructure>
        </item>
        </item>
        </item>
</_:RequestStructure>

</item>
</item>
</item>

#####====> AUD57 - ACTION
        </item>
        </item>
        </item>
</_:RequestStructure>

<!-- out side AUD -->
<_:RequestStructure>
        </item>
        </item>
        </item>
</_:RequestStructure>



Thanks for the time spend on this.

Last edited by Franklin52; 11-13-2009 at 08:07 AM.. Reason: Please use code tags!
# 6  
Old 11-13-2009
9 items??

Can you be more specific?
Do you want the output between the first "#####====> AUD57" and the first "</_:RequestStructure>"?
# 7  
Old 11-13-2009
yes 9 items.

Code:
#####====> AUD57 - ACTION 
<_:RequestStructure>
        </item> ****
        </item> ****
        </item> ****
</_:RequestStructure>  ======== 3

then ....
#####====> AUD57 - ACTION
<_:RequestStructure>
        </item>
        </item>
        </item>
 </_:RequestStructure> ======== 3

then...
....
#####====> AUD57 - ACTION
        </item>
        </item>
        </item>
</_:RequestStructure> ========= 3

So, 9 should be final result.

Last edited by Franklin52; 11-13-2009 at 08:27 AM.. Reason: Please use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Two files String compare

file1.txt col1 col2 col3 b100:07-24-2018:test1 b102:04-24-2017:test2 b103:04-24-2017:test3 b104:04-24-2017:test3 file2.txt col4 col5 b100:name1@email.com b102:name2@email.com b103:name3@email.com Comparing string from file1.txt(col1) each record with... (3 Replies)
Discussion started by: ramgk5
3 Replies

2. Shell Programming and Scripting

How to compare multiple files in UNIX?

Hi, I have below query related to multiple file comparing I have four files i want to compare it and contents of one file will not be presence in 3other files and if any content found then it will print the execution. Can you please help me how to achieve it. (2 Replies)
Discussion started by: soumyamihp
2 Replies

3. Shell Programming and Scripting

Compare the string in different files

Hi, There is a file A.txt which contains a list of strings. A.txt QASSBRK1 QASSBRK2 And in B.txt, command is written to generate output of dspmq with AWK script B.txt QMGR=`dspmq | awk '{print $1}' | cut -f2 -d "(" | cut -f1 -d ")"` Output of B.txt is QASSBRK1 QASSBRK2 QASSBRK3... (4 Replies)
Discussion started by: Anusha M
4 Replies

4. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies

5. Shell Programming and Scripting

Compare multiple files, and extract items that are common to ALL files only

I have this code awk 'NR==FNR{a=$1;next} a' file1 file2 which does what I need it to do, but for only two files. I want to make it so that I can have multiple files (for example 30) and the code will return only the items that are in every single one of those files and ignore the ones... (7 Replies)
Discussion started by: castrojc
7 Replies

6. Shell Programming and Scripting

Compare multiple columns from 2 files

Hi, I need to compare multiple columns from 2 files. I can, for example, have these 2 files: file1: col1, col2, col3,col4 a,1,4,7 b,2,5,8 c,3,6,9file2: col1, col2, col3,col4 a,2,3,2 b,5,7,5 c,1,9,8As a result, I need for example the difference between the columns 2 and 4: col2,... (3 Replies)
Discussion started by: Subbeh
3 Replies

7. Shell Programming and Scripting

Compare multiple files with multiple number of columns

Hi, input file1 abcd 123 198 xyz1:0909090-0909091 ghij 234 999 xyz2:987654:987655 kilo 7890 7990 xyz3:12345-12357 prem 9 112 xyz5:97-1134 input file2 abcd 123 198 xyz1:0909090-0909091 -9.122 0 abed 88 98 xyz1:98989-090808 -1.234 1.345 ghij 234 999 xyz2:987654:987655 -10.87090909 5... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

8. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

9. Shell Programming and Scripting

compare multiple files and get the difference

Hi all, i have 50 files .data should be same in these 50 files , so my task is to find the difference. i need a logic , which finds difference between all files and print in output file with file name where it found that difference . i tried below logic , but its not giving me what i want. let... (2 Replies)
Discussion started by: deepakiniimt
2 Replies

10. Shell Programming and Scripting

compare string in two files

i have two files: file1.txt AA BB DD EE file2.txt AA,AAA BB,BBB CC,CCC DD,DDD EE,EEE FF,FFF i want an output file: file3.txt AA,AAA BB,BBB (2 Replies)
Discussion started by: MiLKTea
2 Replies
Login or Register to Ask a Question