Reputation: 631
I've been searching stackoverflow, and I can't find anyone comparing strings to log files.Is it possible to match the strings in the first column of csv file to a log file?
when it match: print true in the third column
otherwise: print undetected
for example:
heading1 heading2 heading3
5bfa1989e2f6e4a6af9ff62930f462e6b8632212 blablabla true
56ef50c4b83c17e03400d129de99869d8ab18c94 blablabla undetected
Assuming my log file has scrambled text like this:
1537763092 0 1 1 1537734291 1537734291 1537734291 8224 93 364544 5bfa1989e2f6e4a6af9ff62930f462e6b8632212.blabla Troj.Win32.TRX.XXPE50FFF026 c:\users\administrator\desktop\downloader\download\ TRENDX 172.20.4.179 Administrator QllZad 2.0.0.0 5bfa1989e2f6e4a6af9ff62930f462e6b8632212 AAAAAAAAAAQAIQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
Upvotes: 1
Views: 99
Reputation: 49
Yes, it is possible. Something like this worked for me:
import csv
logfile = open('test_log.log', 'r')
log = logfile.read().split(" ") #Read the log file and split on space
with open('data.csv','r') as csvfile:
reader = csv.reader(csvfile)
for line in reader:
if line[0] in log:
print(line[0])
Note that if you want to write back to the csv, you need to read the whole csv, make changes, then write to file.
Upvotes: 1