file_replace_lines

Ensure that a line in a file is replaced by another one.

⚙️ Compatible targets: Linux

Parameters

NameDocumentation
pathFile name to edit (absolute path on the target node).

This parameter is required.
lineLine to match in the file.

This parameter is required.
replacementLine to add in the file as a replacement.

This parameter is required.

Example

method: file_replace_lines
params:
  line: VALUE
  replacement: VALUE
  path: 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.

Example

Here is an example to remove enclosing specific tags

file_replace_lines("/PATH_TO_MY_FILE/file", "<my>(.*)<pattern>", "my ${match.1} pattern")