knowledge/technology/applications/cli/hck.md

28 lines
3 KiB
Markdown
Raw Normal View History

2023-12-04 10:02:23 +00:00
---
obj: application
repo: https://github.com/sstadick/hck
---
2024-03-19 08:25:42 +00:00
2023-12-04 10:02:23 +00:00
# hck
2024-01-17 08:44:04 +00:00
_`hck` is a shortening of `hack`, a rougher form of `cut`._
2023-12-04 10:02:23 +00:00
A close to drop in replacement for cut that can use a regex delimiter instead of a fixed string. Additionally this tool allows for specification of the order of the output columns using the same column selection syntax as cut (see below for examples).
2024-01-17 08:44:04 +00:00
No single feature of `hck` on its own makes it stand out over `awk`, `cut`, `xsv` or other such tools. Where `hck` excels is making common things easy, such as reordering output fields, or splitting records on a weird delimiter. It is meant to be simple and easy to use while exploring datasets. Think of this as filling a gap between `cut` and `awk`.
2023-12-04 10:02:23 +00:00
## Usage
Usage: `hck [options]`
Options:
| Option | Description |
| ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `-o, --output <OUTPUT>` | Output file to write to, defaults to `stdout` |
| `-d, --delimiter <DELIMITER>` | Delimiter to use on input files, this is a substring literal by default. To treat it as a literal add the `-L` flag<br>\[default: `\s+`] |
| `-L, --delim-is-literal` | Treat the delimiter as a string literal. This can significantly improve performance, especially for single byte delimiters |
| `-I, --use-input-delim` | Use the input delimiter as the output delimiter if the input is literal and no other output delimiter has been set |
| `-D, --output-delimiter <OUTPUT_DELIMITER>` | Delimiter string to use on outputs<br>[default: "\t"] |
| `-f, --fields <FIELDS>` | Fields to keep in the output, ex: 1,2-,-5,2-5. Fields are 1-based and inclusive |
| `-e, --exclude <EXCLUDE>` | Fields to exclude from the output, ex: 3,9-11,15-. Exclude fields are 1 based and inclusive. Exclude fields take precedence over `fields` |
| `-E, --exclude-header <EXCLUDE_HEADER>` | Headers to exclude from the output, ex: '^badfield.\*$'. This is a string literal by default. Add the `-r` flag to treat as a regex |
| `-F, --header-field <HEADER_FIELD>` | A string literal or regex to select headers, ex: '^is\_.\*$'. This is a string literal by default. add the `-r` flag to treat it as a regex |
| `-r, --header-is-regex` | Treat the header_fields as regexs instead of string literals |