How to Use the choose Command in Linux as a Fast Alternative to cut and awk

Extracting specific columns from log files, CSV documents, and terminal command outputs is a routine task in Linux shell scripting and data wrangling. For decades, system administrators have relied on cut and awk. However, cut struggles with irregular whitespace delimiters and cannot parse negative indices backwards, while awk '{print $1, $3}' syntax can feel verbose for quick ad-hoc tasks. choose is a fast, human-friendly command-line utility written in Rust that provides intuitive column slicing with Python-style syntax.

Why Developers Use choose Instead of cut or awk

Developed with speed and convenience in mind, choose brings modern ergonomics to command-line text processing:

  • Python-Style Indexing and Slicing: Supports intuitive 0-based indices, half-open ranges (e.g. :3 or 2:), step intervals, and negative indexing (e.g. -1 for the final column).
  • Smart Delimiter Handling: By default, collapses consecutive whitespace characters (tabs and multiple spaces) automatically, parsing formatted terminal tables (like ps or ls) without tedious regex flags.
  • High Performance: Implemented in Rust, choose processes multi-gigabyte log dumps significantly faster than Python scripts and rivals compiled C utilities.
  • Custom Input and Output Delimiters: Easily parses CSVs or TSVs and formats extracted results with custom separators on output.

Installing choose on Linux Distributions

You can install choose through native packages or via Cargo:

  • Arch Linux and Manjaro:
    sudo pacman -S choose
  • Cargo (Universal Rust Installation):
    cargo install choose
  • Homebrew for Linux:
    brew install choose-rust
  • Pre-compiled Binary: Download the pre-built release binary directly from the official GitHub releases page and move it into /usr/local/bin/choose.

Everyday Usage Examples and Command Syntax

The syntax for choose is clean and memorable:

choose [OPTIONS] <CHOICES>...

1. Extracting Specific Columns

To print the first and third columns of a command output (remembering that choose uses 0-based indexing):

ps aux | choose 0 10

This command prints the process owner (column 0) and the running command binary (column 10), automatically collapsing irregular column spacing.

2. Slicing Ranges of Fields

To select a continuous range of columns, use familiar slice notation:

  • First Three Columns:
    cat access.log | choose :3
  • From the Fourth Column to the End:
    cat server.log | choose 3:
  • Columns 2 Through 5:
    cat data.txt | choose 1:5

3. Grabbing the Last Column with Negative Indexing

In standard cut, retrieving the final column of a variable-length row requires awkward combinations of rev | cut | rev. With choose, simply use -1:

df -h | choose 0 -1

This outputs the filesystem name (index 0) and the mount point (the last field, index -1) directly.

4. Parsing Comma-Separated Values (CSV)

To process CSV datasets, pass the -f flag to define the field delimiter:

choose -f "," 0 2 4 < users.csv

To format the output with tabs rather than commas, combine with the output delimiter flag -o:

choose -f "," -o "\t" 0 2 < users.csv

Shell Scripting Best Practices

When incorporating choose into shell pipelines and automated deployment scripts, keep these tips in mind:

  • Index Offsets: Remember that unlike cut and awk (which start counting columns from 1), choose uses 0-based counting (matching Python, JavaScript, and C).
  • Character Slicing: Add the -c flag to slice individual character ranges rather than space-delimited words, providing a fast substitute for cut -c.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.