shoenig / fields Goto Github PK
View Code? Open in Web Editor NEWfields extracts columns of text (replace awk/cut)
Home Page: https://sethops1.net/post/extract-columns-with-fields/
License: MIT License
fields extracts columns of text (replace awk/cut)
Home Page: https://sethops1.net/post/extract-columns-with-fields/
License: MIT License
Currently fields
can handle column definitions in the form of single digits or spans of digits
(e.g. 1,2,3,4,5
or 1-5
). It would be nice if we could have fields print columns like "everything after i'th index" or "everything to left of i'th index". We could use notation like 1+
and -5
to indicate right and left expansions respectively.
it's probably reasonable to just skip empty lines
[x1 ~] $ cat example.txt
a b c
e f
g
[x1 ~] $ cat example.txt | fields 1
a
e
g
fatal: column 0 is out of range [0,-1]
Would be nice to be able to publish snaps of fields to Canonical's snap catalog, and call that our official distribution channel
just causes a panic
[x1 ~] $ fields 1:-2 <<< "a b c d e f g"
panic: runtime error: index out of range
goroutine 1 [running]:
gophers.dev/cmds/fields.zip(0xc000012440, 0x4, 0x4, 0xc0000a4280, 0x7, 0xa, 0x0, 0xc0000b6000, 0x203000)
/home/hoenig/go/src/gophers.dev/fields/apply.go:90 +0x17d
gophers.dev/cmds/fields.process(0xc000018480, 0xd, 0x512c60, 0xc00000e018, 0x512b00, 0xc00000c240, 0x8, 0x18)
/home/hoenig/go/src/gophers.dev/fields/apply.go:52 +0x120
gophers.dev/cmds/fields.Apply(0x512b00, 0xc00000c240, 0x512c40, 0xc00000e010, 0x512c60, 0xc00000e018, 0x0, 0x512ec0)
/home/hoenig/go/src/gophers.dev/fields/apply.go:24 +0x123
main.do(0x0, 0x0, 0x7fff0e0a41db, 0x4, 0x512c40, 0xc00000e010, 0x512c60, 0xc00000e018, 0x0, 0x0)
/home/hoenig/go/src/gophers.dev/fields/cmd/fields/command.go:98 +0xef
main.(*command).Execute(0xc00005bf50, 0xc00000c090, 0x1, 0x1, 0x0)
/home/hoenig/go/src/gophers.dev/fields/cmd/fields/command.go:56 +0x139
main.main()
/home/hoenig/go/src/gophers.dev/fields/cmd/fields/main.go:18 +0x154
Would be nice if there was...
An option to skip N lines
An option to limit processing to N lines
An option to truncate the last N lines
An option to process only the last N lines
Currently fields
only chops columns based on whitespace (tabs and spaces), and processes input on newlines. It'd be nice to be able to specify what to chop fields on other than tabs and spaces. Could go with a set of characters, or maybe a full regexp (or both).
Some argument handling changes broke the way negative indices are handled:
./fields -- -1 <<< "a b c"
fields - CLI columnar text processor [v1]
fields is a tool for selecting columns of text. One or more individual columns
and/or ranges of columns can be selected by index. Indexes can be positive
Need to make them work again
The fields
tool just produces an error when run with no arguments.
$ fields
fatal: expected 1 argument, got 0
An example of a tool that handles this well is jq
which outputs help text when run with no arguments.
$ jq
jq - commandline JSON processor [version 1.5-1-a5b5cbe]
Usage: jq [options] <jq filter> [file...]
jq is a tool for processing JSON inputs, applying the
given filter to its JSON text inputs and producing the
filter's results as JSON on standard output.
The simplest filter is ., which is the identity filter,
copying jq's input to its output unmodified (except for
formatting).
For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq
Some of the options include:
-c compact instead of pretty-printed output;
-n use `null` as the single input value;
-e set the exit status code based on the output;
-s read (slurp) all inputs into an array; apply filter to it;
-r output raw strings, not JSON texts;
-R read raw strings, not JSON texts;
-C colorize JSON;
-M monochrome (don't colorize JSON);
-S sort keys of objects on output;
--tab use tabs for indentation;
--arg a v set variable $a to value <v>;
--argjson a v set variable $a to JSON value <v>;
--slurpfile a f set variable $a to an array of JSON texts read from <f>;
See the manpage for more options.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.