The file contents comparison tool writting by Python

Purpose: Compare the contents between ow ticket and swf log.
         It can generate the different contents into different.txt.
perthon version: 3.6.3
Use: python compare.py

import sys

f_ow, f_swf = None, None
p_ow = "F080-OVnvpro-041.txt"
p_swf = 'swf-log.txt'
p_diff = "different.txt"

# reead lines from F080-OVnvpro-041.txt
try:
    f_ow = open(p_ow, "r")
    ow = f_ow.readlines()
    
    for i in range(len(ow)):
        ow[i] = ow[i].lstrip()
    
except IOError:
    print(p_ow + " does not exist!")
    sys.exit(2)
finally:
    if f_ow:
        f_ow.close()

# reead lines from swf-log.txt
try:
    with open(p_swf,'+r') as f:
        t1 = f.read()
        #Move the Read offset to the beginning
        f.seek(0, 0)
        t2 = t1.replace('/nvpro/branches/released/F080/src/nv/etc', 'install')
        f.write(t2)

    f_swf = open(p_swf, "r")
    swf = f_swf.readlines()
    
except IOError:
    print(p_swf + " does not exist!"  )
    sys.exit(2)
finally:
    if f_swf:
        f_swf.close()

#filter
for a in ow:
    for b in swf:
        if a == b:
            swf.remove(b)

for i in range(len(swf)):
    swf[i] = swf[i].strip()

#print swf
#print " ".join(swf)
for diff in swf:
    with open(p_diff,"a") as fdif:
        fdif.write(diff+"\n")


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值