通过脚本传参数可以实现替换 # -*-coding:utf-8-*- # Author:sunhao import sys f = open('yesterday','r',encoding='utf-8') f_new = open('yesterday.bak','w',encoding='utf-8') find_str=sys.argv[1] replace_str=sys.argv[2] for line in f: if find_str in line: line=line.rep…
shell sed 替换功能 f1 = open('yesterday','r',encoding='utf-8') f2 = open('yesterday2','w',encoding='utf-8') for line in f1: if '噢 昨日当我年少轻狂'in line: line = line.replace('噢 昨日当我年少轻狂','啦啦啦啦啦啦啦啦啦') f2.write(line) f1.close() f2.close() 要替换的文件: Somehow, it see…
#可以用来修改配置文件参数 # -*- coding:utf-8 -*- import os,sys old = sys.argv[1] new = sys.argv[2] file = sys.argv[3] file2 = sys.argv[3] tmp_file ="tmpfile" f = open(file,"r") f2 = open(tmp_file,"r+") for line in f: if old in line: line…