#column #cli #extract #stdin #range #negative #end

app colx

Extract the specified columns from FILES or stdin

3 stable releases

new 1.0.2 Mar 9, 2025
1.0.1 Mar 8, 2025
1.0.0 Mar 7, 2025

#378 in Command line utilities

Download history 134/week @ 2025-03-02

136 downloads per month

Custom license

29KB
644 lines

colx

Extract the specified columns from FILES or stdin.

Column numbering starts at 1, not 0; column 0 is the entire line, just like awk. Column numbers that are out of bounds are silently ignored. When each line is split, empty leading or trailing columns will be discarded before columns are extracted.

Negative column numbers are accepted; -1 is the last column, -2 is the second last, etc. Note that negative column numbers may not behave as you expect when files have a variable number of columns per line: e.g. in line 1 column -1 is column 10, but in line 2 column -1 is column 5. You need to put -- before the first negative column number, otherwise it will be interpreted as a non-existent option.

Column ranges of the form 3:8, -3:1, 7:-7, and -1:-3 are accepted. Both start and end are required for each range. It is not an error to specify an end point that is out of bounds for a line, so 3:1000 will print all columns from 3 onwards (unless you have a very long line).

Usage

Usage: colx [OPTIONS] [COLUMNS_THEN_FILES]...

Arguments:
  [COLUMNS_THEN_FILES]...
          Leading arguments that look like column specifiers are used as
          column specifiers, then remaining arguments are used as filenames

Options:
  -d, --delimiter <DELIMITER>
          Regex delimiting input columns; defaults to whitespace

  -s, --separator <SEPARATOR>
          Separator between output columns; defaults to a single space

Example

$ grep ^root: /etc/passwd | colx -d : -s '!!!' 1 5
root!!!System Administrator

Installation

colx is written in Rust and so needs a Rust toolchain for installation. See https://www.rust-lang.org/tools/install for how to install Rust. When Rust is installed colx can be installed from crates.io with:

cargo install colx

There are no pre-built binaries available, contributions to provide binaries are welcome.

License

Licensed under the Apache 2.0 licence, see the LICENSE file accompanying the software.

Dependencies

~3–4.5MB
~83K SLoC