Replaces all instances of a pattern within a specified file. When using this method make sure that the pattern being used to match does not match the replacement text, otherwise the results may be undesirable.
docs used to help generate this page.
def test_fun(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]
repl_res = duthost.replace(path="/home/admin/test.txt", reqexp="admin", replace="user")
path
- path to file to be modified- Required:
True
- Type:
String
- Aliases:
dest
destfile
name
- Required:
regexp
- regular expression that will used to match. Uses MULTILINE mode, which means^
and$
match beggining and end of file..
does not match newlines.- Required:
True
- Type:
String
- Required:
after
- regular expression that will be matched to the file content. Only content after this match will be modified.- Required:
False
- Type:
String
- Required:
attributes
- Attributes resulting file or directory should have (look at man page for chattr for supported flags)- Required:
False
- Type:
String
- Aliases:
attr
- Required:
backup
- Create backup file including timestamp to roll back if needed- Required:
False
- Type:
Boolean
- Default:
False
- Required:
before
- Regular expression that will be matched to the file content. Only content before this match will be modified.- Required:
False
- Type:
String
- Required:
encoding
- Character encoding for selected file- Required:
False
- Type:
String
- Default:
utf-8
- Required:
group
- Name of group that should one the file- Required:
False
- Type:
String
- Required:
mode
- permissions for resulting file. Can be written symolically: "u=rw, g=r, o=rx"- Required:
False
- Type:
String
- Required:
owner
- Name of owner that will own the file- Required:
False
- Type:
String
- Required:
replace
- String that will replace the regex matches. If none is provided, all matches are removed.- Required:
False
- Type:
String
- Required:
selevel
- the level part of the Security Enchanced Linux file context- Required:
False
- Type:
String
- Required:
setype
- the type part of the Security Enchanced Linux file context- Required:
False
- Type:
String
- Required:
seuser
- the user part of the Security Enchanced Linux file context- Required:
False
- Type:
String
- Required:
unsafe_writes
- Allow unsafe writes when atomic operations fail (will still do safe writes if they do not)- Required:
False
- Type:
Boolean
- Default:
False
- Required:
validate
- validation command to be run on file- Required:
False
- Type:
Boolean
- Required:
Method provides no useful output.