go-replace

command module
v0.0.0-...-5a5fb2e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 6 Imported by: 0

README ยถ

go-replace

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

GitHub Go

๐Ÿ“ 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

  1. Backup Safety

    • Backup files (*.bak) are created in the same directory
    • Original file permissions are preserved
  2. Pattern Matching

    • Supports standard wildcard patterns:
      • * matches any sequence
      • ? matches any single character
  3. 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.

Documentation ยถ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL