go-replace
CLI tool written in Go to search and replace text in files recursively with backup/restore functionality.

๐ Description
go-replace is a powerful text replacement tool that allows you to:
- Replace text patterns in files across directories
- Create automatic
.bak
backups
- Restore original files from backups
- Clean up backup files
โจ Features
- ๐ Text Replacement - Replace strings in all matching files
- ๐พ Backup System - Auto-create
.bak
files before modification
- โฎ๏ธ ** Restore System** - Revert files from backups
- ๐งน Clean Backups - Delete all
.bak
files
- ๐ Pattern Matching - Target files using wildcard patterns
๐ฅ Installation
Linux Installation
Method 1: From Source
# Clone repository
git clone https://github.com/arwahdevops/go-replace.git
cd go-replace
# Build and install
go build -o go-replace
sudo mv go-replace /usr/local/bin/
Method 2: Go Install
go install github.com/arwahdevops/go-replace@latest
sudo cp $HOME/go/bin/go-replace /usr/local/bin/
๐ Usage
Basic Command Structure
go-replace [OPTIONS] -old "OLD_TEXT" -new "NEW_TEXT"
Common Options
Flag |
Description |
-dir |
Target directory (default: current) |
-pattern |
Filename pattern (e.g., *.txt) |
-old |
Text to replace (required) |
-new |
Replacement text (required) |
-backup |
Create backup files |
-restore |
Restore files from .bak backups |
-clean |
Delete all .bak files |
๐ก Examples
1. Simple Replacement
go-replace -dir docs -pattern "*.md" -old "foo" -new "bar"
2. Safe Replacement with Backup
go-replace -dir src -old "http://" -new "https://" -backup
3. Restore Files
go-replace -dir project -restore
4. Clean Backups
go-replace -dir data -clean
๐ Important Notes
-
Backup Safety
- Backup files (
*.bak
) are created in the same directory
- Original file permissions are preserved
-
Pattern Matching
- Supports standard wildcard patterns:
*
matches any sequence
?
matches any single character
-
Safety First
- Double-check replacement patterns before execution
- Always use
-backup
for critical operations
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.