go-sed
is a simple and efficient command-line tool written in Go for performing basic text transformations, similar to the Unix sed
command.
- Search and replace text in files
- In-place file editing
- Addition of double spacing
- Removal of trailing blank lines
- Suppress automatic printing of pattern space
Basic usage of go-sed
:
$ go run main.go -h
Usage of: go run main.go [options] [script] [filename]
Options:
-i string
edit in-place (default "s/The/Code/g")
-n string
only output a range of lines from the file (default "1p")
Script:
- s/this/that/g
- G
- /^$/d
Filename:
quotes.txt
go run main.go 's/old/new/g' input.txt
s/old/new/g
: Substituteold
withnew
globally in the file
go run main.go -n '2,4p' input.txt
-n '2,4p'
: Only output a range of lines from the file i.e line 2 to line 4
go run main.go -n /code/p input.txt
-n /code/p
: Output only lines containing a specific patterncode
go run main.go G input.txt
G
: Support double spacing a file
go run main.go /^$/d input.txt
/^$/d
: Strip trailing blank lines from a file
go run main.go -i 's/Life/Code/g' intput.txt
-i 's/Life/Code/g'
: Edit in place
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.