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 SHAIn 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
awk Command Reference for CI Scriptsawk is a pattern-scanning text processor for CI. Reference for -F field separator, -v variables, and $1/$NF f…
tr Command Reference for CI Scriptstr translates, squeezes, or deletes characters from stdin in CI. Reference for -d, -s, -c, and ranges, plus t…
sort Command Reference for CI Scriptssort orders lines of text in CI for stable diffs. Reference for -n, -u, -k, -t, and -r, plus the locale gotch…
grep Command Reference for CI Scriptsgrep searches text for matching lines in CI. Reference for -r, -E, -i, -q, and -v, plus the exit-code-1-means…