Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 11 characters in body
Source Link
srgerg
  • 19.4k
  • 4
  • 59
  • 40

Edit: While my solution works correctly, check out Martijn's answer below for a more efficient solution.

You can find the documentation for the python CSV module here.

What you're looking for is something like this:

import csv f1 = file('hosts.csv', 'r') f2 = file('masterlist.csv', 'r') f3 = file('results.csv', 'w') c1 = csv.reader(f1) c2 = csv.reader(f2) c3 = csv.writer(f3) masterlist = [row for row in c2]list(c2) for hosts_row in c1: row = 1 found = False for master_row in masterlist: results_row = hosts_row if hosts_row[3] == master_row[1]: results_row.append('FOUND in master list (row ' + str(row) + ')') found = True break row = row + 1 if not found: results_row.append('NOT FOUND in master list') c3.writerow(results_row) f1.close() f2.close() f3.close() 

You can find the documentation for the python CSV module here.

What you're looking for is something like this:

import csv f1 = file('hosts.csv', 'r') f2 = file('masterlist.csv', 'r') f3 = file('results.csv', 'w') c1 = csv.reader(f1) c2 = csv.reader(f2) c3 = csv.writer(f3) masterlist = [row for row in c2] for hosts_row in c1: row = 1 found = False for master_row in masterlist: results_row = hosts_row if hosts_row[3] == master_row[1]: results_row.append('FOUND in master list (row ' + str(row) + ')') found = True break row = row + 1 if not found: results_row.append('NOT FOUND in master list') c3.writerow(results_row) f1.close() f2.close() f3.close() 

Edit: While my solution works correctly, check out Martijn's answer below for a more efficient solution.

You can find the documentation for the python CSV module here.

What you're looking for is something like this:

import csv f1 = file('hosts.csv', 'r') f2 = file('masterlist.csv', 'r') 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[3] == master_row[1]: results_row.append('FOUND in master list (row ' + str(row) + ')') found = True break row = row + 1 if not found: results_row.append('NOT FOUND in master list') c3.writerow(results_row) f1.close() f2.close() f3.close() 
Corrected some bugs; deleted 34 characters in body
Source Link
srgerg
  • 19.4k
  • 4
  • 59
  • 40

You can find the documentation for the python CSV module here.

What you're looking for is something like this:

import csv f1 = file('hosts.csv', 'r') f2 = file('masterlist.csv', 'r') f3 = file('results.csv', 'w') c1 = csv.reader(f1) c2 = csv.reader(f2) c3 = csv.writer(f3) masterlist = [row for row in c2] for hosts_row in c1: row = 1 found = False for master_row in masterlist: ifresults_row hosts_row[1]= ==hosts_row  master_row[0] and  if hosts_row[3] == master_row[1]: results_row.append('FOUND =in hosts_rowmaster list (row ' + str('FOUNDrow) in+ masterlist',')') else: found = True results_rowbreak  row = hosts_rowrow + 1  if not found: results_row.append('NOT FOUND in masterlist',master list')   c3.writerow(results_row) f1.close() f2.close() f3.close() 

You can find the documentation for the python CSV module here.

What you're looking for is something like this:

import csv f1 = file('hosts.csv', 'r') f2 = file('masterlist.csv', 'r') f3 = file('results.csv', 'w') c1 = csv.reader(f1) c2 = csv.reader(f2) c3 = csv.writer(f3) masterlist = [row for row in c2] for hosts_row in c1: for master_row in masterlist: if hosts_row[1] == master_row[0] and hosts_row[3] == master_row[1]: results_row = hosts_row + ('FOUND in masterlist',) else: results_row = hosts_row + ('NOT FOUND in masterlist',)   c3.writerow(results_row) f1.close() f2.close() f3.close() 

You can find the documentation for the python CSV module here.

What you're looking for is something like this:

import csv f1 = file('hosts.csv', 'r') f2 = file('masterlist.csv', 'r') f3 = file('results.csv', 'w') c1 = csv.reader(f1) c2 = csv.reader(f2) c3 = csv.writer(f3) masterlist = [row for row in c2] for hosts_row in c1: row = 1 found = False for master_row in masterlist: results_row = hosts_row    if hosts_row[3] == master_row[1]: results_row.append('FOUND in master list (row ' + str(row) + ')')  found = True break  row = row + 1  if not found: results_row.append('NOT FOUND in master list') c3.writerow(results_row) f1.close() f2.close() f3.close() 
Source Link
srgerg
  • 19.4k
  • 4
  • 59
  • 40

You can find the documentation for the python CSV module here.

What you're looking for is something like this:

import csv f1 = file('hosts.csv', 'r') f2 = file('masterlist.csv', 'r') f3 = file('results.csv', 'w') c1 = csv.reader(f1) c2 = csv.reader(f2) c3 = csv.writer(f3) masterlist = [row for row in c2] for hosts_row in c1: for master_row in masterlist: if hosts_row[1] == master_row[0] and hosts_row[3] == master_row[1]: results_row = hosts_row + ('FOUND in masterlist',) else: results_row = hosts_row + ('NOT FOUND in masterlist',) c3.writerow(results_row) f1.close() f2.close() f3.close()