Skip to content
Latchkey

cut Command Reference for CI Scripts

cut pulls specific columns (fields, characters, or bytes) from each line.

cut is the lightweight column extractor. Its main limitation versus awk: the delimiter is a single character and runs of whitespace are not collapsed.

Common flags/usage

  • -f LIST: select fields (1, 2-4, 3-)
  • -d CHAR: field delimiter (single char, default TAB)
  • -c LIST: select character positions
  • -b LIST: select byte positions
  • --complement: invert the selection (GNU only)

Example

shell
echo "${GITHUB_REF}" | cut -d/ -f3-       # refs/heads/main -> main
cut -d, -f1,3 results.csv
git log -1 --format='%H' | cut -c1-7      # short commit SHA

In CI

The delimiter must be a single character; you cannot split on a string or regex (use awk for that). cut does not collapse multiple spaces, so columns aligned with variable spacing come out wrong; pre-process with tr -s or use awk. --complement is GNU-only and missing on BSD/macOS.

Key takeaways

  • cut splits on a single delimiter character only; use awk for strings or regex.
  • It does not collapse repeated spaces, so squeeze whitespace first when needed.
  • Field ranges like 2- and 1,3 select open-ended and discontinuous columns.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →