Documentation ¶
Overview ¶
Package sed implements the classic UNIX sed language in pure Go. The interface is very simple: a user compiles a program into an execution engine by calling New or NewQuiet. Then, the engine can Wrap() any io.Reader to lazily process the stream as you read from it.
All classic sed commands are supported, but since the package uses Go's regexp package for the regular expressions, the syntax for regexps will not be the same as a typical UNIX sed. In other words, instead of: s|ab\(c*\)d|\1|g you would say: s|ab(c*)d|$1|g. So this is a Go-flavored sed, rather than a drop-in replacement for a UNIX sed. Depending on your tastes, you will either consider this an improvement or completely brain-dead.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the compiled instruction stream for a sed program. It is the main type that users of the go-sed library will interact with.
func New ¶
New creates a new sed engine from a program. The program is executed via the Run method. If the provided program has any errors, the returned engine will be 'nil' and the error will be returned. Otherwise, the returned error will be nil.
func NewQuiet ¶
NewQuiet creates a new sed engine from a program. It behaves exactly as New(), except it produces an engine that doesn't print lines by defualt. This is the classic '-n' sed behaviour.
func (*Engine) RunString ¶
RunString executes the program embodied by the Engine on the given string as input, returning the output string and any errors that occured.