Skip to content
Latchkey

cut -c: Extract Columns by Character

cut -c selects characters by their position on the line, good for fixed-width output.

Some tool output is fixed-width rather than delimited. cut -c slices by column position instead of by field.

What it does

cut -c keeps the characters at the listed positions, numbered from 1. Ranges work the same as fields: -c1-8 keeps the first eight characters, -c10- keeps from position 10 to end. It ignores delimiters entirely and works purely on position.

Common usage

Terminal
cut -c1-8 timestamps.txt          # first 8 chars
cut -c1 answers.txt               # just the first character
git log --oneline | cut -c1-7     # short commit hashes

Options

FlagWhat it does
-c <list>Character positions to keep, e.g. 1-8 or 1,5,9
-c N-From position N to end of line
-c -NFrom start to position N
--complementKeep all characters except those listed
--output-delimiter=<s>Insert a separator between selected ranges

In CI

cut -c is ideal for fixed-width logs and for trimming hashes to a short prefix. For variable-width columns use -f with a delimiter instead, since positions will not line up.

Common errors in CI

In a UTF-8 locale, GNU cut -c counts characters, so a multibyte character may not align with a byte offset; use cut -b to count bytes when you need byte positions. BSD/macOS cut historically treats -c as bytes, so the same command can slice differently across runner platforms.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →