file_replace_lines
Ensure that a line in a file is replaced by another one.
⚙️ Compatible targets: Linux
Parameters
Name | Documentation |
---|---|
path | File name to edit (absolute path on the target node). This parameter is required. |
line | Line to match in the file. This parameter is required. |
replacement | Line to add in the file as a replacement. This parameter is required. |
Outcome conditions
You need to replace ${path}
with its actual canonified value.
- ✅ Ok:
file_replace_lines_${path}_ok
- ☑️ Already compliant:
file_replace_lines_${path}_kept
- 🟨 Repaired:
file_replace_lines_${path}_repaired
- ☑️ Already compliant:
- ❌ Error:
file_replace_lines_${path}_error
Example
method: file_replace_lines
params:
replacement: VALUE
path: VALUE
line: VALUE
Documentation
You can replace lines in a files, based on regular expression and captured pattern
Syntax
The content to match in the file is a PCRE regular expression, unanchored that you can replace with the content of replacement.
Content can be captured in regular expression, and be reused with the notation ${match.1}
(for first matched
content), ${match.2}
for second, etc, and the special captured group ${match.0}
for the whole text.
This regular expression must not match the string used as a replacement.
For example, to set kernel.shmmax=5678
, the regular expression would be kernel.shmmax=(?!5678$).*
and the string used as replacement kernel.shmmax=5678
Note that if you want to replace a key-value line, method File key-value present
is more suited.
Example
Here is an example to remove enclosing specific tags
file_replace_lines("/PATH_TO_MY_FILE/file", "<my>(.*)<pattern>", "my ${match.1} pattern")