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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VenkatMC
    New Member
    • Aug 2015
    • 2

    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
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    VenkatMC,

    Please post your code so we can review it.

    How big is your list of words in "File_B"?

    Comment

    • VenkatMC
      New Member
      • Aug 2015
      • 2

      #3
      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.

      Code:
      #!/usr/bin/perl -w
      
      my $find = "a2billing";
      open LOGFILE, "<File_A.txt";
      my @line = <LOGFILE>;
      print "Lines that matched : $find\n";
      
      for (@line)
       {
          if ($_ =~ /$find/)
          {
                    if($_ =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
              {
                      print "$_\n";
              }
      
          }
      }
      close LOGFILE;
      Last edited by Rabbit; Aug 14 '15, 05:42 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

      Comment

      Working...