473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to compare each and every line in File_A with the every line in File_B

I have httpd logs in File_A and some suspecious keywords in File_B. Now i need to compare the every line in File_A with each and every keyword present in File_B. if the keyword in File_B found in any line of File_A then print that entire line of File_A. How can i compare those two files in perl

File_A Contents :

210.254.85.193 - - [23/Apr/2015:17:40:39 +0900] "GET / HTTP/1.1" 200 9369 a2billing
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/css/style.css HTTP/1.1" 200 8623
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/js/testproxy HTTP/1.1" 200 1533
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/images/bg_header.gif HTTP/1.1" 200 150
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/images/navi_01_current.gif HTTP/1.1" 200 2533
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/images/navi_05.gif HTTP/1.1" 200 1907
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/images/bg_fla.jpg connectxml HTTP/1.1" 200 563
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/images/h1_logo.gif HTTP/1.1" 200 3781
210.254.85.193 - - [23/Apr/2015:17:40:40 +0900] "GET /Asset/common/images/txt_topcopy.gif vtigercrm HTTP/1.1" 200 1954



File_B Contents:

a2billing
testporxy
vtigercrm
connectxml
Aug 13 '15 #1
2 2161
RonB
589 Expert Mod 512MB
VenkatMC,

Please post your code so we can review it.

How big is your list of words in "File_B"?
Aug 13 '15 #2
Here is my code. By using this code i'm comparing the contents of File_A with the predefined string in $fine variable...But i need to read it from File_B. I'm stucked while reading from File_B and compare with File_A.

File_B contains the keywords added daily and these keywords are the suscpecious activity keywords in http log files.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. my $find = "a2billing";
  4. open LOGFILE, "<File_A.txt";
  5. my @line = <LOGFILE>;
  6. print "Lines that matched : $find\n";
  7.  
  8. for (@line)
  9.  {
  10.     if ($_ =~ /$find/)
  11.     {
  12.               if($_ =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
  13.         {
  14.                 print "$_\n";
  15.         }
  16.  
  17.     }
  18. }
  19. close LOGFILE;
Aug 14 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joe Richett | last post by:
Hi all, I have a python program and I have some "user defined" command stored in a separate text file. Is there a builtin command with which I can load the "user defined"-file and execute every...
6
by: Rolf Brauser | last post by:
Hello, is it possible to draw a one pixel line around every cell in a table? with "border: 1px solid; " just the outer tableborder ist concerned ? thanks for any help rolf
2
by: malauddin | last post by:
Hi all, I am looking for a regular expression to find a word at the beginning of a line and then read the entire line. From the example below, I want to find the word "FN" and then read entire...
0
by: Sushil Srivastava | last post by:
Hi Guys, I have developed a utility that provide a smart MSDN knowledge base search both off-line and on-line. I have describe more in detail below why I decided to write this utility (one...
11
by: jamx | last post by:
I need to compare the following values: char buf; /* buf is filled using COMport here... */ if (buf == 0x85) { /* do something */ }
2
by: scsoce | last post by:
I want to profile a function which has some lines of statement. It seem that profile module only report function's stats instead of every line of code, how can i profile every line of code?...
14
by: lashaw | last post by:
This program display a names. If the name you type match the one asked to type, the program tells you the phone number of the name. The problem is it only list the last name in the file. How to get...
1
by: anil cha | last post by:
I have to grep a file from line n1 and n2. Is there a single command unix to do that?
0
by: SEhtesham | last post by:
Hi, I have my application in VS2008 and coded Vb.net. My query is i want to save record from an excel sheet to my Database Table. But i dont want to insert the Excel sheet as a whole...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.