ssh_file_replace_line_multi
Replace a matching line in a file with a list of new lines via SSH. Options to delete the line or insert an empty line.
Instructions
Replace a unique line in a file with multiple new lines.
PARAMETERS:
file_path: Path to the file to modify
match_line: Exact line content to match and replace (whitespace-trimmed)
new_lines: List of new lines to insert in place of the match
To replace with multiple lines: use ["first line", "second line", ...]
To delete the line entirely: use [] (empty list)
To replace with an empty line: use [""]
use_sudo: Use sudo for the operation (default: false)
force: Force operation even if file can't be read (sudo only) (default: false)
RETURNS: A dictionary with operation status including:
success: Boolean indicating if operation succeeded
file_path: Path to the modified file
EXAMPLES: Example 1: Replace a line with multiple lines
{
"file_path": "/etc/hosts",
"match_line": "127.0.0.1 localhost",
"new_lines": ["127.0.0.1 localhost", "127.0.0.1 myhost.local"]
}Example 2: Delete a line entirely
{
"file_path": "/etc/nginx/nginx.conf",
"match_line": "# server_tokens off;",
"new_lines": []
}Example 3: Replace with an empty line
{
"file_path": "/etc/ssh/sshd_config",
"match_line": "PermitRootLogin yes",
"new_lines": [""]
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the file to modify | |
| match_line | Yes | Exact line content to match and replace | |
| new_lines | Yes | List of new lines to insert in place of the match | |
| use_sudo | No | Use sudo for the operation | |
| force | No | Force operation even if file can't be read (sudo only) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||