Skip to content

Simple tool for efficiently replacing bytes within a stream of bytes.

License

Notifications You must be signed in to change notification settings

spatialcurrent/goreplacer

Repository files navigation

CircleCI Go Report Card GoDoc license

goreplacer

Description

goreplacer is a simple tool for efficiently replacing bytes within a stream of bytes.

Platforms

The following platforms are supported. Pull requests to support other platforms are welcome!

GOOS GOARCH
darwin amd64
linux amd64
windows amd64
linux arm64

Releases

Find releases at https://github.com/spatialcurrent/goreplacer/releases. You might want to rename your binary to just goreplacer. See the Building section below to build from scratch.

Darwin

  • goreplacer_darwin_amd64 - CLI for Darwin on amd64 (includes macOS and iOS platforms)

Linux

  • goreplacer_linux_amd64 - CLI for Linux on amd64
  • goreplacer_linux_amd64 - CLI for Linux on arm64

Windows

  • goreplacer_windows_amd64.exe - CLI for Windows on amd64

Usage

See the usage below or the following examples.

goreplacer is a simple tool for for efficiently replacing bytes within a stream of bytes.
Replacements are encoded as a 2 dimensional JSON array of a series of replacement pairs ([OLD, NEW]).
If the positional argument is "-" or not given, then reads from stdin.

Usage:
  goreplacer [--lines] [--max MAX] [--replacements] '[[OLD1, NEW1], [OLD2, NEW2], ...]' [-|FILE]

Flags:
  -h, --help                  help for goreplacer
  -l, --lines                 process as lines
  -n, --max int               maximum number of replacements (default -1)
  -r, --replacements string   replacements encoded as 2-dimensional JSON array, i.e., [[OLD1, NEW1], [OLD2, NEW2], ...]

Examples

Replace words

cat FILE | goreplacer -r '[["world", "planet"]]'

Update Copyright

cat FILE | goreplacer -n 1 -r '[["Copyright (C) 2019", "Copyright (C) 2020"]]'

Unescape Double Quotes

$ echo '{""hello"":""world""}' | goreplacer -r '[["\"\"","\""]]'
{"hello":"world"}

Replace Single Quotes with Double Quotes

$ echo "{'hello':'world'}" | goreplacer -r "[[\"'\",\"\\\"\"]]"
{"hello":"world"}

Building

Use make help to see help information for each target.

CLI

The make build_cli script is used to build executables for Linux and Windows. Use make install for standard installation as a go executable.

Changing Destination

The default destination for build artifacts is bin, but you can change the destination with an environment variable. For building on a Chromebook consider saving the artifacts in /usr/local/go/bin, e.g., DEST=/usr/local/go/bin make build_cli

Testing

CLI

To run CLI testes use make test_cli, which uses shUnit2. If you recive a shunit2:FATAL Please declare TMPDIR with path on partition with exec permission. error, you can modify the TMPDIR environment variable in line or with export TMPDIR=<YOUR TEMP DIRECTORY HERE>. For example:

TMPDIR="/usr/local/tmp" make test_cli

Go

To run Go tests use make test_go (or bash scripts/test.sh), which runs unit tests, go vet, go vet with shadow, errcheck, ineffassign, staticcheck, and misspell.

Contributing

Spatial Current, Inc. is currently accepting pull requests for this repository. We'd love to have your contributions! Please see Contributing.md for how to get started.

License

This work is distributed under the MIT License. See LICENSE file.

About

Simple tool for efficiently replacing bytes within a stream of bytes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published