是否可以 运行 sed,如果不存在则追加到 fabric 中?
Is it possible to run sed, if not exists append in fabric?
是否可以运行如果某行某行存在则修改,如果不存在则追加文字?
类似
modified = sed('file.txt', before = 'to be replaced', after = 'expected')
if(!modified):
append('file.txt', 'expected')
你真的可以!
查看此内容,了解如何使用 Python sed:How to do sed like text replace with python?
代码将是这样的:
file = 'file.txt'
before = 'to be replaced'
after = 'expected'
if before in file:
sed(before, expected)
else:
append(file, after)
是否可以运行如果某行某行存在则修改,如果不存在则追加文字?
类似
modified = sed('file.txt', before = 'to be replaced', after = 'expected')
if(!modified):
append('file.txt', 'expected')
你真的可以!
查看此内容,了解如何使用 Python sed:How to do sed like text replace with python?
代码将是这样的:
file = 'file.txt'
before = 'to be replaced'
after = 'expected'
if before in file:
sed(before, expected)
else:
append(file, after)