匹配文件某一行起始字符,替换整行__自动化脚本

匹配开头,替换一整行

change = [1.0, 2.0, 3.0]

# 替换后的字符串
change_str = "objectStorage_fileStorage_coefficient = {}".format(change[0])

# sed -i 插入修改, /^匹配头, 然后 /c替换后的串
cmd = r"sed -i '/^objectStorage_fileStorage_coefficient/c{}' {}".format(\
    change_str, "/etc/cluster-manager/cluster-manager_copy.conf")
print(cmd)
val = os.system(cmd)
print(val)

你可能感兴趣的:(shell,Python,搞机)