[root@localhost python]# cat modify_db.py#!/usr/bin/pythonimport osdir ='/data/script/shell/bak3303_201308011221'dir2='/data/script/python/out_db/'files=os.listdir(dir)for f in files: print f file1=os.path.join(dir,f) file_object=open(file1,'r') all_the_txt=file_object.read() file2=all_the_txt.replace('DEFINER=`root`@`%`','') file_object2=os.path.join(dir2,f) file_object3=open(file_object2,'w') file_object3.write(file2) file_object.close() file_object3.close()
遍历dir文件夹下的内容,进行DEFINER=`root`@`%`替换成空格,最后按原文件名保存到dir2文件夹下。