Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compare file csv
#1
im working on a comparasion of csv file. The problem is that the files have different structure and the comparation work bad.. can anyone help me? Thank you.

import csv
f1 = file('Report.csv', 'r') #hosts 
f2 = file('p.csv', 'r') #master log file
f3 = file('results.csv', 'w')

c1 = csv.reader(f1)
c2 = csv.reader(f2) #
c3 = csv.writer(f3)

masterlist = list(c2)

for hosts_row in c1:
    row = 1
    found = False
    for master_row in masterlist:
        results_row = hosts_row
        
        if (hosts_row[1]).split(',') == master_row[1]:
			
            results_row.append('FOUND in log file (row ' + str(row) + ')')
            found = True
            break
        row = row + 1
    if not found:
        results_row.append('NOT FOUND in log file')
    c3.writerow(results_row)

f1.close()
f2.close()
f3.close()
p.csv
MrLog - PortScan Analysis results		
		
Date		
13 Dec 14		
IP		
xxx.xxx.xx.xxx			
IP	            start port	end port
xxx.xxx.xx.xxx	        5161	5165
xxx.xxx.xx.xxx          5061	5069
report.csv
ipv vvv.vvv.vvv
mach1 xxx.xxx.xxx
port
xxxxx
xxx
xxx

mach2 xxx.xxx.xxx
port
xxx
xxx
xxxx
Reply
#2
you need to provide a symbol meaning map.

expected values, format,  and ranges of xxx.xxx.xxx
without that, you could just as well ask us to compare cows to jet planes.
what exactly should match??
Reply
#3
(Sep-01-2017, 10:43 PM)Larz60+ Wrote: you need to provide a symbol meaning map.
sorry man, xxx.xxx.xxx symbols mean a random ip, example: 192.168.83.141, 192.168.83.144,109.232.137.3
etc. etc.. the goal is a comparison to see if there are equality, the same for ports.
Reply
#4
Are those actual contents of the csv files?  Because neither of them are... csv files.  One is tab-separated, and the other is just a single column, where the meaning of each row is dependent upon the preceding row(s).  As it currently stands, I'm not sure using the csv module will help more than it'll hurt, since the files are mostly nonsense.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 126 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,071 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Compare variable with values in a file paulo79 1 1,079 Apr-22-2022, 03:16 AM
Last Post: Pedroski55
  Python csv compare two file, update value if two value is matched kinojom 1 2,516 Apr-17-2019, 10:36 AM
Last Post: DeaD_EyE
  Compare all words in input() to all words in file Trianne 1 2,716 Oct-05-2018, 06:27 PM
Last Post: ichabod801
  Compare element of list with line of file : if match, delete line silfer 4 3,477 Jul-21-2018, 02:44 PM
Last Post: silfer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020