No description
Find a file
Ryan Geary 389c29822b Improve performance and add profiling tooling
Add tags, todo, *.bench, *.svg and bench_output to .gitignore

Add test/bench.sh script. bench.sh runs the `bench` command on each
test/long*txt file with range 3:5 and saves the output to a file for
comparing performance across file sizes.

Inline printing in get_choice_slice

Change BufWriter<..stdout..> to BufWriter<T>

Add MockStdout for testing printing

Add more reverse range tests

Simplify word finding with a more uniform bounds check.

Add Makefile for generating flamegraphs

Redefine Choice struct as a start and end integer

Improve algorithm for finding words to print

Settle exclusivity at Config construction time

Add tests for nonexistant field_seps

Add regression test for preceding separator

Use handle.write instead of write! macro for tremendous speed up
2020-03-10 00:03:14 -04:00
src Improve performance and add profiling tooling 2020-03-10 00:03:14 -04:00
test Improve performance and add profiling tooling 2020-03-10 00:03:14 -04:00
.gitignore Improve performance and add profiling tooling 2020-03-10 00:03:14 -04:00
Cargo.lock Bump version in Cargo.toml 2019-09-29 17:52:20 -04:00
Cargo.toml Bump version in Cargo.toml 2019-09-29 17:52:20 -04:00
Makefile Improve performance and add profiling tooling 2020-03-10 00:03:14 -04:00
readme.md Add compilation instructions 2019-09-17 22:06:04 -04:00

Choose

This is choose, a human-friendly alternative to awk and cut

Rationale

The AWK programming language is designed for text processing and is extremely capable in this endeavor. However, the awk command is not ideal for rapid shell use, with its requisite quoting of a line wrapped in curly braces, even for the simplest of programs:

awk '{print $1}'

Likewise, cut is far from ideal for rapid shell use, because it is difficult to get the confusing syntax correct on the first attempt. Field separators and ranges are just plain difficult to use.

It is for these reasons that I present to you choose. It is not meant to be a drop-in or complete replacement for either of the aforementioned tools, but rather a simple and intuitive tool to reach for when the basics of awk or cut will do, but the overhead of getting them to behave should not be necessary.

Usage

`choose` sections from each line of files

USAGE:
    choose [FLAGS] [OPTIONS] <choice>...

FLAGS:
    -d, --debug        Activate debug mode
    -h, --help         Prints help information
    -n, --inclusive    Use inclusive ranges
    -V, --version      Prints version information

OPTIONS:
    -f, --field-separator <field-separator>    Specify field separator other than whitespace
    -i, --input <input>                        Input file

ARGS:
    <choice>...    Fields to print. Either x, x:, :y, or x:y, where x and y are integers, colons indicate a range,
                   and an empty field on either side of the colon continues to the beginning or end of the line.

Examples

choose 5                # print the 5th item from a line (zero indexed)

choose -f ':' 0 3 5     # print the 0th, 3rd, and 5th item from a line, where
                        # items are separated by ':' instead of whitespace

choose 2:5              # print everything from the 2nd to 5th item on the line,
                        # exclusive of the 5th

choose -n 2:5           # print everything from the 2nd to 5th item on the line,
                        # inclusive of the 5th

choose :3               # print the beginning of the line to the 3rd item,
                        # exclusive

choose 3:               # print the third item to the end of the line

Compilation and Installation

In order to build choose you will need rust installed, and you can find instructions for that here.

Then, to install:

git clone https://github.com/theryangeary/choose.git
cd choose
cargo build --release
install target/release/choose <DESTDIR>

Just make sure DESTDIR is in your path.