替换文件中字符串的脚本

# 打开文件并读取内容
with open('/etc/network/interfaces.d/eth0', 'r') as file:
    file_content = file.read()
# 将所有的字符串192.168.1.91替换为192.168.5.91
new_content = file_content.replace('192.168.1.91', '192.168.5.91')
# 写入替换后的内容回文件
with open('/etc/network/interfaces.d/eth0', 'w') as file:
    file.write(new_content)
print("替换完成")

在armbian中测试成功

posted @ 2023-11-14 17:27  王者之心的笔记  阅读(18)  评论(0)    收藏  举报