Multi Edit
Performs multiple find-and-replace operations on a single file efficiently in one atomic operation.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
Inputs
- File Path -
string- Absolute path to the file to modify (required). - Edits -
array- Array of edit operations to perform sequentially (required). Each edit must have:old_string(string, required) - The text to findnew_string(string, required) - The replacement textreplace_all(bool, optional) - Whether to replace all occurrences (default: false)
Outputs
- File Path -
string- Path to the edited file. - Total Replacements -
int- Total number of replacements made across all edits. - Modified -
bool- Whether the file was actually modified. - Edit Results -
array- Detailed results for each edit operation including:index- Edit operation indexold_string- The search stringnew_string- The replacement stringreplace_all- Whether all occurrences were replacedreplacements- Number of replacements madesuccess- Whether the edit succeedederror- Error message if the edit failed
How It Works
The Multi Edit node performs multiple string replacements in sequence on a single file. When executed, the node:
- Validates the file path and edits array
- Verifies each edit operation has valid old_string and new_string
- Ensures old_string and new_string are different for each edit
- Reads the file content once
- Applies each edit operation sequentially:
- Searches for old_string in the current file state
- For replace_all=false: Validates uniqueness
- Performs the replacement
- Updates the file content for the next edit
- Writes the modified content atomically only once
- Returns detailed results for each edit operation
Requirements
- Valid absolute file path
- File must exist
- At least one edit operation
- Each edit must have non-empty old_string
- Each old_string must be different from its new_string
- For single replacements: old_string must be unique
Error Handling
The node will return specific errors in the following cases:
- Missing file path - "File path is required"
- Missing edits - "Edits array is required"
- Relative path - "File path must be absolute"
- Directory traversal - "Path cannot contain '..' for security reasons"
- File not found - "File not found:
{{path}}" - Invalid edits format - "Invalid edits format:
{{error}}" - No edits provided - "At least one edit operation is required"
- Empty old_string - "Edit
{{N}}: old_string cannot be empty" - Identical strings - "Edit
{{N}}: old_string and new_string must be different" - String not found - "Edit
{{N}}failed: String not found:{{string}}" - Multiple occurrences - "Edit
{{N}}failed: String appears{{count}}times. Use replace_all or provide more context" - Read error - "Failed to read file:
{{error}}" - Write error - "Failed to write file:
{{error}}"
Usage Examples
Multiple Configuration Updates
Update several configuration values:
File Path: /home/user/app/config.json
Edits: [
{
"old_string": "\"port\": 8080",
"new_string": "\"port\": 9000",
"replace_all": false
},
{
"old_string": "\"debug\": true",
"new_string": "\"debug\": false",
"replace_all": false
},
{
"old_string": "\"host\": \"localhost\"",
"new_string": "\"host\": \"production.example.com\"",
"replace_all": false
}
]
Code Refactoring
Rename multiple identifiers in one operation:
File Path: /home/user/src/module.py
Edits: [
{
"old_string": "oldClassName",
"new_string": "NewClassName",
"replace_all": true
},
{
"old_string": "old_function_name",
"new_string": "new_function_name",
"replace_all": true
},
{
"old_string": "OLD_CONSTANT",
"new_string": "NEW_CONSTANT",
"replace_all": true
}
]
Template Substitution
Replace multiple placeholders:
File Path: /home/user/templates/email.html
Edits: [
\{
"old_string": "\{\{USER_NAME\}\}",
"new_string": "John Doe",
"replace_all": true
\},
\{
"old_string": "\{\{EMAIL\}\}",
"new_string": "john@example.com",
"replace_all": true
\},
\{
"old_string": "\{\{DATE\}\}",
"new_string": "2024-01-15",
"replace_all": true
\}
]
Sequential Dependencies
Apply changes that depend on previous changes:
File Path: /home/user/data/report.txt
Edits: [
{
"old_string": "Status: pending",
"new_string": "Status: in_progress",
"replace_all": false
},
{
"old_string": "Status: in_progress",
"new_string": "Status: completed",
"replace_all": false
}
]
Usage Notes
- Edits are applied sequentially, not simultaneously
- Each edit sees the result of all previous edits
- The file is only written once, after all edits complete
- If any edit fails, no changes are written to the file
- All edits must succeed for the operation to complete
- Edit order matters when changes affect subsequent searches
- The operation is atomic - the file is never in an incomplete state
- Original file permissions are preserved
- Each edit in the results array shows success status and details
Common Use Cases
Bulk Configuration Updates
Update multiple settings in configuration files in one operation.
Multi-Step Refactoring
Rename multiple related identifiers (classes, functions, variables).
Template Processing
Replace multiple placeholders in template files.
Version Updates
Update version strings, copyright years, and related metadata together.
Data Migration
Update multiple data format changes in structured text files.
Batch Text Corrections
Fix multiple typos or standardize terminology in one pass.
Best Practices
- Order matters: Place edits in logical sequence if they affect each other
- Validate first: Use Read node to verify current content before editing
- Include context: For single replacements, include enough context to ensure uniqueness
- Group related changes: Combine related edits to minimize file I/O
- Check results: Examine Edit Results output to verify all edits succeeded
- Handle failures: Check the success field for each edit in the results
- Test with small changes: Test edit operations on a copy before applying to important files
Performance Benefits
- Single file read: Content is read only once
- Single file write: All changes written atomically in one operation
- Efficient processing: Changes applied in memory before writing
- Reduced I/O: Much faster than multiple Edit node calls
- Atomic operation: Either all changes apply or none do
Comparison with Other Nodes
- Multi Edit vs Edit: Multi Edit applies multiple changes; Edit applies one change
- Multi Edit vs Multiple Edit Nodes: Multi Edit is faster and atomic for multiple changes
- Multi Edit vs Write: Multi Edit modifies existing content; Write replaces entire file