SedX
A safe, modern replacement for GNU
sedwith automatic backups, preview mode, and one-command rollback.
SedX is a modern stream editor written in Rust that maintains ~90% compatibility with GNU sed while adding critical safety features:
- Automatic backups before every file modification
- Preview mode to see changes before applying
- One-command rollback to undo mistakes
- Human-readable diffs with colored context
- Streaming mode for large files (100GB+ with <100MB RAM)
- Modern regex (PCRE) as the default
Table of Contents
- Quick Start
- Why SedX?
- Installation
- Basic Usage
- Regex Modes
- Common Operations
- Backup & Rollback
- Pipeline Mode
- Large Files
- Configuration
- Command Reference
- Limitations
- Examples
- Migration from GNU sed
Quick Start
# Install
# Preview changes before applying
# Apply safely (automatic backup created)
# Rollback if needed
Why SedX?
GNU sed is powerful but unforgiving—one mistake with -i can permanently corrupt your files. SedX gives you the same power with safety rails:
| Feature | GNU Sed | SedX |
|---|---|---|
| Preview changes | ❌ No | ✅ --dry-run |
| Automatic backups | ❌ No | ✅ Yes (default) |
| Rollback | ❌ No | ✅ sedx rollback |
| Colored diffs | ❌ No | ✅ Yes |
| Streaming for 100GB+ files | ⚠️ Requires tweaks | ✅ Auto-detects |
| Default regex | BRE (1970s) | ✅ PCRE (modern) |
Key difference: SedX uses PCRE (Perl-Compatible Regular Expressions) by default—the same regex flavor used in Perl, Python, JavaScript, and most modern tools. No more escaping parentheses!
Installation
From crates.io (Recommended)
From Source
From GitHub Releases
Download the latest release from Releases and add to your PATH.
Basic Usage
Substitution
# Replace first occurrence on each line
# Replace all occurrences (global)
# Case-insensitive substitution
# Numbered substitution (replace 3rd occurrence)
Line-Specific Operations
# Operate on specific line
# Operate on lines matching pattern
Deleting Lines
# Delete specific line
# Delete range
# Delete matching lines
# Delete from pattern to end
Multiple Commands
# Using multiple -e flags
# Using command grouping with semicolons
# Grouping with range
Regex Modes
SedX supports three regex flavors, selectable via command-line flags:
PCRE (Default) - Modern Syntax
- Unescaped metacharacters:
(),{},+,?,|,. - Backreferences in replacement:
$1,$2, etc. - Most powerful and familiar to modern developers
ERE Mode - sed -E Compatible
- Extended Regular Expressions
- Compatible with
sed -Eand BSD sed - Same syntax as PCRE for most operations
BRE Mode - GNU sed Compatible
- Basic Regular Expressions (GNU sed default)
- Escaped metacharacters:
\(\),\{\},\+,\?,\| - Backreferences in replacement:
\1,\2(converted to PCRE internally)
Backreference Conversion
| Mode | Pattern Syntax | Replacement Syntax |
|---|---|---|
| PCRE | (foo|bar) |
$1, $2 |
| ERE | (foo|bar) |
\1, \2 (auto-converted to $1, $2) |
| BRE | \(foo|bar\) |
\1, \2 (auto-converted to $1, $2) |
Common Operations
Print Commands
# Print specific lines
# Print line numbers
Insert, Append, Change
# Insert text before line 5
# Append text after line 5
# Replace line 5 with new text
# Change lines matching pattern
Hold Space Operations
# Copy pattern space to hold space
# Exchange pattern and hold space
# Append to hold space
Flow Control
# Labels and branches
# Conditional branch (if substitution made)
# Branch if NO substitution made
Backup & Rollback
Every file modification automatically creates a backup in ~/.sedx/backups/:
# Apply changes (backup created automatically)
# Output: Backup ID: 20260226-120000-abc123
# View backup history
# Rollback last operation
# Rollback specific backup
# Check backup status
Backup Management
# List all backups
# Clean old backups (keep last 10)
# Use custom backup directory
Disable Backups
# Skip backup (requires --force confirmation)
⚠️ Warning: Use --no-backup only for files under version control where you can revert mistakes.
Pipeline Mode
When no files are specified, SedX reads from stdin and writes to stdout:
# Basic pipeline
|
# Output: HELLO world
# Chain with other commands
| |
# Filter logs
|
# Multiple commands in pipeline
|
# Output: TEST CASE
Pipeline mode characteristics:
- ✅ No backups created (can't backup a stream)
- ✅ No diff output (only transformed text)
- ✅ Works with all regex modes (PCRE, ERE, BRE)
- ✅ Exit status: 0 on success, non-zero on errors
Large Files
SedX automatically switches to streaming mode for files ≥100MB:
# Automatically uses streaming for large files
# Force streaming mode
# Disable streaming (force in-memory)
Streaming benefits:
- Constant memory usage (<100MB regardless of file size)
- Can process 100GB+ files efficiently
- Sliding window diff for context around changes
Configuration
Create or edit ~/.sedx/config.toml:
[]
= 10 # Maximum backup size
= 80 # Warn before using this much disk
= "/custom/path" # Custom backup location
[]
= "pcre" # Default regex: pcre, ere, or bre
= true # Show compatibility warnings
[]
= 2 # Default diff context lines
= 100 # Streaming threshold (file size)
= true # Enable streaming mode
# Edit configuration
# View current configuration
Command Reference
Options
| Option | Description |
|---|---|
-e, --expression <EXPR> |
Add a sed expression (can be used multiple times) |
-f, --file <SCRIPT_FILE> |
Read script from file |
-d, --dry-run |
Preview changes without modifying files |
-i, --interactive |
Prompt before applying changes |
--context <NUM> |
Number of context lines in diff (default: 2) |
--no-context |
Show only changed lines |
-n, --quiet |
Suppress automatic output (only p command shows output) |
-B, --bre |
Use Basic Regular Expressions (GNU sed compatible) |
-E, --ere |
Use Extended Regular Expressions (sed -E compatible) |
--no-backup |
Skip backup (requires --force) |
--force |
Force dangerous operations |
--backup-dir <DIR> |
Custom backup directory |
--streaming |
Enable streaming mode |
--no-streaming |
Disable streaming mode |
-h, --help |
Print help |
-V, --version |
Print version |
Subcommands
| Command | Description |
|---|---|
rollback [ID] |
Undo last operation or specific backup |
history |
Show operation history |
status |
Show backup status and disk usage |
backup list |
List all backups |
backup prune --keep=N |
Keep only N most recent backups |
config |
Edit configuration file |
config --show |
View current configuration |
help |
Print help message |
Limitations
SedX aims for ~90% GNU sed compatibility. The following are NOT yet implemented:
| Feature | Status | Alternative |
|---|---|---|
y command (translate characters) |
Not supported | Use multiple s commands |
l command (list lines escaped) |
Not supported | N/A |
\L, \U in replacement (case conversion) |
Not supported | Post-process with other tools |
Word boundaries \<, \> |
Not supported | Use \b in PCRE mode |
Known Issues
See tests/KNOWN_ISSUES.md for detailed limitations.
Examples
Config File Updates
# Preview version update
# Apply
Log File Cleanup
# Remove all DEBUG lines
# Keep only ERROR lines
Batch File Processing
# Process multiple files
# With specific directory
Complex Pattern Matching
# Email address redaction (PCRE default)
# Remove duplicate words
# Number lines (add prefix)
Migration from GNU sed
Simple Substitutions
No changes needed—syntax is identical:
# GNU sed
# SedX (same syntax)
Regex Patterns
GNU sed (BRE) → SedX (PCRE default)
# GNU sed
# SedX Option 1: Use PCRE (recommended)
# SedX Option 2: Use BRE mode for exact compatibility
In-Place Editing
# GNU sed (destructive)
# SedX (safe with backup)
# SedX (no backup, like GNU sed)
Extended Regex
# GNU sed with -E
# SedX with -E (same behavior)
# SedX default (PCRE syntax same as ERE)
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
# Run tests
# Run integration tests
# Format code
# Lint
License
MIT License - see LICENSE for details.
Support
Made with ❤️ and Rust by InkyQuill