fields

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 6 Imported by: 0

README

fields

Use fields to chop input into selectable columns.

Go Report Card Build Status GoDoc NetflixOSS Lifecycle GitHub

Get it from the Snap Store

Project Overview

Module gophers.dev/cmds/fields provides a command-line utility for processing columns of input text.

Getting Started

Install from SnapCraft

The fields command can be installed as a snap

$ sudo snap install fields
Build from source

The fields command can be compiled by running

$ go get gophers.dev/cmds/fields/cmd/fields

Example Usages

select a single column (from left)
$ fields 3 <<< "a b c d e f g"
c
select a single column (from right)
$ fields -- -3 <<< "a b c d e f g"
e
select multiple columns
$ fields 1,-1,2,-2 <<< "a b c d e f g"
a g b f
select columns to the right of N (from left)
$ fields 4: <<< "a b c d e f g"
d e f g
select columns to the right of N (from right)
$ fields -- -2: <<< "a b c d e f g"
f g
select columns to the left of N (from left)
$ fields :2 <<< "a b c d e f g"
a b
select columns to the left of N (from right)
$ fields :-2 <<< "a b c d e f g"
a b c d e f
select range of columns
$ fields 2:5 <<< "a b c d e f g"
b c d e
any combination of the above, all together
$ fields 1,2,-2,3:5,2:,:-3 <<< "a b c d e f g"
a b f c d e b c d e f g a b c d e

Contributing

The gophers.dev/cmds/fields module is always improving with new features and error corrections. For contributing bug fixes and new features please file an issue.

License

The gophers.dev/cmds/fields module is open source under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(columns Columns, input io.Reader, output io.Writer) error

Apply will actually select the desired columns from the input and write them back out into the output in the same order in which they were requested.

Types

type Columns

type Columns interface {
	// Columns returns the set of selected columns given a length of input.
	Columns(int) []int
}

Columns is used to actually select on columns of an input.

func Combine

func Combine(cols []Columns) Columns

func Components

func Components(s string) ([]Columns, error)

Components returns a Spanner which is a superset of one or more other Spanner which can used to describe the columns to be selected.

Example: "1,-3:-4,5:"

type Spanner

type Spanner interface {
	Spans(string) (Columns, error)
}

Spanner needs to parse things in the formats: 1, -1 (single) (- means count back from right) 1:5 (range) 1: (right-expansion) (i.e. from this column to the right) :5 (left-expansion) (i.e. from this column to the left) and any combination of thereof.

func Single

func Single(s string) (Spanner, error)

Single returns a Spanner which is capable of interpreting s as one item that can be parsed as one or more columns.

Examples: "1", "-3:-4", "5:"

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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