Extracting specific columns and delimiters from structured log files, CSV exports, and command outputs is a cornerstone of Linux data wrangling. For decades, developers have turned to the standard GNU cut utility for basic extraction or written verbose awk scripts for non-trivial delimiters. However, GNU cut suffers from fundamental constraints: it cannot reorder output columns, cannot parse multi-character or regular expression delimiters, and lacks negative indexing. The open-source Rust-based utility hck solves these legacy limitations while delivering exceptional multi-threaded performance.
What Is hck and Why Choose It Over cut and awk?
Engineered with hardware SIMD acceleration and parallel parsing pipelines, hck functions as a drop-in, modern replacement for cut with several substantial enhancements:
- Arbitrary and Regex Delimiters: Natively supports multi-character strings, whitespace runs (
\s+), and complex regular expressions without falling back to heavy scripting languages. - Arbitrary Field Reordering: Unlike standard
cut(which always prints extracted fields in their original document order),hckrespects the precise ordering specified in your flags. Specifying-f 3,1outputs column 3 followed by column 1. - Negative Index Slicing: Supports Python-style negative indices. Requesting
-f -1isolates the final column of every line regardless of how many fields precede it. - Header-Aware Column Extraction: For CSV and TSV files, pass
-Hto select columns by their descriptive header names rather than counting column indices manually.
Installing hck on Linux
Depending on your distribution and environment, you can install hck via Cargo, distribution packages, or direct release binaries.
Method 1: Installing via Cargo
If you have Rust and Cargo configured on your machine, compile and install hck from crates.io:
cargo install --locked hck
Ensure that your local Cargo binary folder (~/.cargo/bin) is present in your active $PATH.
Method 2: Installing on Arch Linux
Arch Linux users can install hck through the Arch User Repository (AUR) using an AUR helper such as yay:
yay -S hck
Method 3: Installing Pre-Compiled Release Binaries
For Debian, Ubuntu, Fedora, and Red Hat systems, download the pre-compiled binary from GitHub:
curl -s https://api.github.com/repos/sstadick/hck/releases/latest \
| grep "browser_download_url.*x86_64-unknown-linux-musl.tar.gz" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -
tar -xzf hck-*-x86_64-unknown-linux-musl.tar.gz
sudo mv hck /usr/local/bin/
Everyday Usage and Practical Examples
The command syntax of hck mirrors cut with intuitive flags: -d specifies the input delimiter, -D sets the output delimiter, and -f defines the fields.
1. Splitting on Whitespace Runs and System Outputs
Extracting columns from tools like ps or df traditionally fails in cut because columns are separated by multiple spaces. With hck, match whitespace automatically using regex:
df -h | hck -d '\s+' -f 1,5,6
2. Reordering Output Columns
If you need to rearrange CSV fields so identifiers appear first:
cat users.csv | hck -d ',' -f 3,1,2
Column 3 will print first, followed by Column 1 and Column 2, formatted with commas.
3. Using Negative Indexing to Extract Final Columns
To inspect the login shell assigned to accounts in /etc/passwd without counting intervening colon fields:
hck -d ':' -f 1,-1 /etc/passwd
This command extracts the initial username (field 1) and the final login binary (field -1) directly.
4. Extracting Columns by CSV Header Name
When working with large analytics datasets containing dozens of attributes, counting numbers is error-prone. Use the -H flag to filter by header strings:
hck -d ',' -H -f 'TransactionID,Amount,Status' sales_q3.csv
5. Changing Output Delimiters Dynamically
To convert comma-separated values into tab-separated or pipe-separated records while extracting:
hck -d ',' -D '\t' -f 1-4 data.csv
Benchmarking Performance on Large Files
Because hck uses memory mapping (mmap), custom core routines, and multi-threaded line chunking, it processes multi-gigabyte files up to five times faster than GNU cut and over ten times faster than standard awk scripts, making it an essential addition to any high-throughput data processing pipeline.