python删除文件中含"指定内容"的行
2013-01-14 16:41
483 查看
#!/bin/env python import shutil, sys, os darray = [ "Entering directory", "In function ", "Leaving directory", "__NR_SYSCALL_BASE", "arm-hisiv100-linux-ar ", "arm-hisiv100-linux-gcc ", "but argument is of type", "dereferencing type-punned pointer will break strict-aliasing rules", "differ in signedness", "does break strict-aliasing rules", "embedded '\\0' in format", "excess elements in array initializer", "implicit declaration of", "make -C ", " rm -f", "this is the location of the previous definition", "warning: multi-line comment" ] def isInArray (array, line): for item in array: if item in line: return True return False if __name__ == '__main__': argv = sys.argv argc = len(argv) if argc < 2: print "Usage: %s <file>" %(os.path.basename(argv[0])) exit() fname = argv[1] fresult = fname + ".result" with open(fname, 'r') as f: with open(fresult, 'w') as g: for line in f.readlines(): if not isInArray(darray, line): g.write(line)
另参考:
bash删除文件中含"指定内容"的行
相关文章推荐
- Python实现删除文件中含“指定内容”的行示例
- Python_删除/创建指定目录及其下所有子目录的文件,该文件记录当前文件夹的内容
- bash删除文件中含"指定内容"的行
- 【Python/PE】python中实现文件操作的几种功能(删除指定目录下的所有内容,文件复制等)
- Python_删除/创建指定目录及其下所有子目录的文件,该文件记录当前文件夹的内容
- python目录遍历和删除指定目录下的pyc文件
- php实现遍历目录并删除指定文件中指定内容
- python 删除指定时间间隔之前的文件实例
- python 查找指定内容的txt文件
- 删除指定路径根目录所有文件-python
- python 按指定规则批量删除多级目录中的文件
- 删除指定文件的python脚本
- VC MFC删除指定文件或文件夹内容
- Windows API函数删除指定文件目录下所有内容vc6.0通过
- 第三百四十一节,Python分布式爬虫打造搜索引擎Scrapy精讲—编写spiders爬虫文件循环抓取内容—meta属性返回指定值给回调函数—Scrapy内置图片下载器
- python脚本删除指定路径下指定类型的文件
- 用Python脚本来删除指定容量以上的文件的教程
- Linux bash删除文件中含“指定内容”的行功能示例
- python之删除指定后缀名文件
- 遍历INI文件和删除指定域内容