tuc
A more powerful field cutter with regex delimiters, negative indexes, and flexible output formatting.
tuc extends the familiar cut command with capabilities that the POSIX
original lacks. It supports positive and negative field indexes, ranges,
field reordering, and multi-character or regex delimiters — all things that
make cut awkward or impossible for real-world data.
Output formatting goes beyond simple field extraction. You can join selected
fields with a custom delimiter, replace the original delimiter in the output,
emit fields as a JSON array, or use {} placeholder syntax to construct
arbitrary output strings from named fields.
tuc can cut by fields, bytes, characters, or lines, and handles UTF-8 correctly throughout. It also supports memory-mapped files for efficient processing of large inputs and NUL-terminated input for working with null-delimited data streams.
Basic usage
echo "foo bar baz" | tuc -d ' ' -f 3,2,1 # Reorder fields: baz bar foo.
echo "foo bar baz" | tuc -d ' ' -f '{1}, {2} and {3}' # Format output.
echo "foo bar baz" | tuc -d ' ' --json # Emit as a JSON array.
echo "a,b, c" | tuc -e '[, ]+' -f 1,3 # Use a regex delimiter.
printf "a\nb\nc\nd\ne" | tuc -l 2:-2 # Cut lines with a negative index.