Need help in comparing a file with log file: perl code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in comparing a file with log file: perl code
# 1  
Old 11-24-2009
Need help in comparing a file with log file: perl code

Dear Members,

I need a perl code:
1. Which will open first file with two columns separated by tab:

37 Distribution and seasonal variation of trace metals
85 Seasonal variability of the mixed layer in the central Bay
99 Dynamics of transparent exopolymeric particles (TEP)
103 Bacterial extracellular polymeric substances (EPS): A carrier

2. Then open web server log files from a folder as per the first column of each line from the first file (such as 37.txt or 85.txt or 99.txt 103.txt etc).

3. Then take the words separated by space (except a, an, the, of, and, etc) from the 2nd column of respective line of first file and count the words, count1++
4. Match the words from $line first files in the 2nd file (log file) each $line. For each word match in each $line of 2nd file, do count2++

5. The required out put file format is

first column (IP) of 2nd file (i.e. log file) tab(\t) count2++ tab(\t) value of count2++/count1++

Extracted Log hits in a file 103.txt as follows:


59.144.4.65 - - [05/Aug/2006:11:53:23 +0530] "GET /drs/bitstream/2264/103/3/Environ_Int_32_191.pdf HTTP/1.1" 200 383974 "http://www.google.co.in/search?q=bioremediation+of+heavy+metals&hl=en&lr=&start=110&sa=N" "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7"
200.27.127.33 - - [08/Aug/2006:03:08:51 +0530] "GET /drs/bitstream/2264/103/3/Environ_Int_32_191.pdf HTTP/1.1" 200 383974 "http://www.google.cl/search?hl=es&q=concentration+EPS+bacteria&meta=" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"


Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl for comparing numbers from previous lines in a file?

Hi everyone I have a question for you, as I am trying to learn more about Perl and work with some weather data. I have an ascii file (shown below) that has 10 lines with different columns. What I would like is have Perl find an "anomalous" value by comparing a field with the values from the last... (2 Replies)
Discussion started by: lucshi09
2 Replies

2. Shell Programming and Scripting

Script for Comparing directories and file from a text file

Hello all, I need to write a script which has following requirement: Need to read the filenames from text file and then search for the above read files in the required directory and if match found backup them in a backup folder. And also need to compare and verify whether the files in the... (7 Replies)
Discussion started by: saurau
7 Replies

3. Shell Programming and Scripting

Retrieve data from one file comparing the ID in the second file

Hi all, I have one file with IDs Q8NDM7 P0C1S8 Q8TF30 Q9BRP8 O00258 Q6AWC2 Q9ULE0 Q702N8 A4UGR9 Q13426 Q6P2D8 Q9ULM3 A8MXQ7 I want to compare ID file with another file which has complete information about these IDs and also about other IDs which are not in the above ID file. As... (10 Replies)
Discussion started by: kaav06
10 Replies

4. Shell Programming and Scripting

PERL code to check if file exists

Hi Guy’s, I have this simple PERL code which checks whether the file exists . At the moment I am getting the following error This is the code I am using #!/usr/bin/perl Open (F, "home/work/PerlWork/dataFile") or die "Could not open the file:$!\"; Also how can I read the content of... (3 Replies)
Discussion started by: INHF
3 Replies

5. Shell Programming and Scripting

Remove duplicate lines from first file comparing second file

Hi, I have two files with below data:: file1:- 123|aaa|ppp 445|fff|yyy 999|ttt|jjj 555|hhh|hhh file2:- 445|fff|yyy 555|hhh|hhh The records present in file1, not present in file 2 should be writtent to the out put file. output:- 123|aaa|ppp 999|ttt|jjj Is there any one line... (3 Replies)
Discussion started by: gani_85
3 Replies

6. Programming

Perl- How to catch the file in perl code?

Hi, plz see the below code , i have catch the file "Orders.20110714.out "file as a Orders*.out. but it giving me an error .it does not open the file. if the same thing i have done by code code-> ls Orders*.out then it gives me the output Orders.20110714.out i am trying apply the... (1 Reply)
Discussion started by: pspriyanka
1 Replies

7. Shell Programming and Scripting

Perl's buffered I/O is causing me to miss latest log file entries in log colorizer. How to fix?

I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable. The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Discussion started by: rcsteiner
1 Replies

8. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

9. Shell Programming and Scripting

Comparing rows in same file and writing the result in new file

Help needed... Can you tell me how to compare the last two couple entries in a file and print their result in new file..:confused: I have one file Check1.txt \abc1 12345 \abc2 12327 \abc1 12345 \abc2 12330 I want to compare the entries in Check1 and write to... (1 Reply)
Discussion started by: kichu
1 Replies

10. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies
Login or Register to Ask a Question