Manipulate list output from difflib.differ
Hi,
I am comparing 2 txt files that are ls -R of the etc directory in a linux system. I compared the 2 files using difflib.differ and got this list as my result (i put the dots to keep the list short in here):
[' etc:\n',
' ArchiveSEL\n',
' HOSTNAME\n',
' RMCPUser\n',
.
.
.
' qcleaner\n',
'+ extraFile\n',
' rc.d\n',
' resolv.conf\n',
.
.
.
' xinetd.d\n',
' \n',
' etc/cmm:\n',
.
.
.
' wu-ftpd\n']
I want to be able to take the string with the '+' sign out to do something else. how do i manipulate the list?
my python script goes like this:
file1 = "c:/cmmlog/etc1.txt"
file2 = "c:/cmmlog/etc2.txt"
f1 = open(file1)
f2 = open(file2)
d = difflib.Differ()
result = list(d.compare(f1.readlines(), f2.readlines()))
_pprint (result)
f1.close()
f2.close()
Hi,
I am comparing 2 txt files that are ls -R of the etc directory in a linux system. I compared the 2 files using difflib.differ and got this list as my result (i put the dots to keep the list short in here):
[' etc:\n',
' ArchiveSEL\n',
' HOSTNAME\n',
' RMCPUser\n',
.
.
.
' qcleaner\n',
'+ extraFile\n',
' rc.d\n',
' resolv.conf\n',
.
.
.
' xinetd.d\n',
' \n',
' etc/cmm:\n',
.
.
.
' wu-ftpd\n']
I want to be able to take the string with the '+' sign out to do something else. how do i manipulate the list?
my python script goes like this:
file1 = "c:/cmmlog/etc1.txt"
file2 = "c:/cmmlog/etc2.txt"
f1 = open(file1)
f2 = open(file2)
d = difflib.Differ()
result = list(d.compare(f1.readlines(), f2.readlines()))
_pprint (result)
f1.close()
f2.close()
Last edited: