pipeline

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Filters = map[string]reflect.Value{
		"columns":      reflect.ValueOf(Columns),
		"columnscsv":   reflect.ValueOf(ColumnsCSV),
		"countlines":   reflect.ValueOf(CountLines),
		"countrunes":   reflect.ValueOf(CountRunes),
		"countwords":   reflect.ValueOf(CountWords),
		"first":        reflect.ValueOf(First),
		"!first":       reflect.ValueOf(NotFirst),
		"frequency":    reflect.ValueOf(Frequency),
		"join":         reflect.ValueOf(Join),
		"last":         reflect.ValueOf(Last),
		"!last":        reflect.ValueOf(NotLast),
		"match":        reflect.ValueOf(Match),
		"!match":       reflect.ValueOf(NotMatch),
		"matchregex":   reflect.ValueOf(MatchRegex),
		"!matchregex":  reflect.ValueOf(NotMatchRegex),
		"replace":      reflect.ValueOf(Replace),
		"replaceregex": reflect.ValueOf(ReplaceRegex),
	}
)

Functions

func Columns

func Columns(delimiter string, columns string) func(io.Reader, io.Writer) error

Columns returns a filter that writes the selected 'columns' in the order provided where 'columns' is a 1-indexed comma separated list of column positions. Columns are defined by splitting with the 'delimiter'.

func ColumnsCSV added in v0.1.2

func ColumnsCSV(delimiter string, columns string) func(io.Reader, io.Writer) error

ColumnsCSV returns a CSV aware filter that writes the selected 'columns' in the order provided where 'columns' is a 1-indexed comma separated list of column positions. Columns are defined by splitting with the 'delimiter'.

func CountLines

func CountLines() func(io.Reader, io.Writer) error

CountLines returns a filter that writes the number of lines read.

func CountRunes

func CountRunes() func(io.Reader, io.Writer) error

CountRunes returns a filter that writes the number of runes (utf8 characters) read.

func CountWords

func CountWords() func(io.Reader, io.Writer) error

CountWords returns a filter that writes the number of words (as defined by strings.Fields()) read.

func First

func First(n int) func(io.Reader, io.Writer) error

First returns a filter that writes the first 'n' lines.

func Frequency

func Frequency() func(io.Reader, io.Writer) error

Frequency returns a filter that writes unique lines from the input, prefixed with a frequency count, in descending numerical order (most frequent lines first). Lines with equal frequency will be sorted alphabetically.

This is a common pattern in shell scripts to find the most frequently-occurring lines in a file:

sort testdata/freq.input.txt |uniq -c |sort -rn

Frequency's behaviour is like the combination of Unix `sort`, `uniq -c`, and `sort -rn` used here.

Like `uniq -c`, Freq left-pads its count values if necessary to make them easier to read:

10 apple
 4 banana
 2 orange
 1 kumquat

func Join

func Join(delimiter string) func(io.Reader, io.Writer) error

Join returns a filter that writes all lines as a single string separated by 'delimiter'.

func Last

func Last(n int) func(io.Reader, io.Writer) error

Last returns a filter that writes the last 'n' lines.

func Match

func Match(substring string) func(io.Reader, io.Writer) error

Match returns a filter that writes lines containing 'substring'.

func MatchRegex

func MatchRegex(regex *regexp.Regexp) func(io.Reader, io.Writer) error

MatchRegex returns a filter that writes lines matching the compiled regular expression 'regex'.

func NewPipeline

func NewPipeline(r io.Reader) *pipeline

NewPipeline returns new pipeline given a io.Reader.

func NotFirst

func NotFirst(n int) func(io.Reader, io.Writer) error

NotFirst returns a filter that writes lines after the first 'n' lines.

func NotLast

func NotLast(n int) func(io.Reader, io.Writer) error

NotLast returns a filter that writes up to the last 'n' lines.

func NotMatch

func NotMatch(substring string) func(io.Reader, io.Writer) error

NotMatch returns a filter that writes lines not containing 'substring'.

func NotMatchRegex

func NotMatchRegex(regex *regexp.Regexp) func(io.Reader, io.Writer) error

NotMatchRegex returns a filter that writes lines not matching the compiled regular expression 'regex'.

func Replace

func Replace(old, replace string) func(io.Reader, io.Writer) error

Replace returns a filter that writes all lines replacing non-overlapping instances of 'old' with 'replace'.

func ReplaceRegex

func ReplaceRegex(regex *regexp.Regexp, replace string) func(io.Reader, io.Writer) error

ReplaceRegex returns a filter that writes all lines replacing matches of the compiled regular expression 'regex' with 'replace'.

Types

This section is empty.

Jump to

Keyboard shortcuts

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