This is my current code. I want to check the two values(lines) to check for matches in the files.
def checkOS():
fid1 = open("C:/Python/NSRLOS.txt", 'r')
fid2 = open("C:/Python/sha_sub_hashes.out", 'r')
outdata = open("osMatches.txt", 'w')
line1 = fid1.readline()
line2 = fid2.readline()
while(line1 and line2):
xline= line1.split(',')[1]
yline = line2.split("|")[3]
zline = xline.replace('"','')
if (yline == zline):
outdata.append([yline , zline])
print xline, zline
if __name__=="__main__":
checkOS()
The only problem is I’m not sure what I’ve written does that, all the code before the if statement is just reformatting to be able to pull from the index of the line. What I want to know is if the statement I used works in that sense and is it efficient? Then I want to output the equal values.
Here are some lines in the files:
file2:
"10","Amstrad 6128","Unknown","1006"
"100","Macintosh 9.0","8.5.1","67"
"101","Macintosh 9.0.4","na","67"
"102","Macintosh 9.1","9.1","67"
"103","Macintosh 9.2","9.2","67"
"104","Macintosh 9.2.2","9.2.2","67"
"105","Macintosh 9.x","9.X","67"
"106","Macintosh X","10","67"
"107","Macintosh7.5.3","7.5.3","67"
"108","NetWare","n/a","674"
"109","Novel Dos 7.0","7","609"
"11","Apple II+","Unknown","67"
"110","OS/2","Unknown","427"
file2:
DD84270022E57F1850C8454FA432ADFF99588157B|index.docbook|2225|Redhat 7.3 (32bit)|Linux
D84270022E57F1850C8464F5432ADFF99588157B|index.docbook|2225|Redhat 8.0 (32bit)|Linux
26EEEB25D7005F9FF9EE05A8084C77242702FBAD|Localizable.strings|2142|Mac OS X 10.4|OSX
34DC3D728C34E32F090307F575254D57E53C53FF|SYSTEM|10747904|Windows 7 Home Premium (32bit)|Windows
279E5A766C88EEA5AB946A0AF8D0C4FC366B2AF9|totem.devhelp|21324|Linux Ubuntu Desktop 9.10 (32bit)|Linux
279E5A766C88EEA5AB964A0AF8D0C4FC366B2AF9|totem.devhelp|21324|Linux Ubuntu Desktop 9.10 (64bit)|Linux
B3D11390AB8683BBE443A415EDD91BFDFD482134|dslconfig.pyc|6246|Redhat 9.0 (32bit)|Linux
Now you probably won’t find any immediate matches in these few lines, but I know that somewhere down the line there will be at least one match because I saw that while skimming through the files.
you’re probably looking for something like this:
use
with()it automatically closes the files for you.