CtrlK
BlogDocsLog inGet started
Tessl Logo

cut

Remove sections from each line of files. Use when extracting columns, fields from CSV/TSV data, or specific character positions.

68

Quality

83%

Does it follow best practices?

Impact

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

SKILL.md
Quality
Evals
Security

cut - Remove Sections from Lines

Synopsis

cut OPTION... [FILE]...

Print selected parts of lines from each FILE to standard output.

Flags

FlagLong FormDescription
-f--fields=LISTSelect only these fields (requires -d)
-d--delimiter=DELIMUse DELIM instead of TAB for field delimiter
-c--characters=LISTSelect only these characters
-b--bytes=LISTSelect only these bytes
-s--only-delimitedDo not print lines not containing delimiters (with -f)
--complementComplement the set of selected bytes, characters, or fields
--output-delimiter=STRINGUse STRING as the output delimiter
-z--zero-terminatedLine delimiter is NUL, not newline
--helpDisplay help
--versionOutput version

LIST Format

Use comma-separated values and/or ranges:

FormatMeaning
NNth byte, character, or field (1-based)
N-From Nth to end of line
N-MFrom Nth to Mth (inclusive)
-MFrom first to Mth

Examples

# Extract second field from TAB-separated data
cut -f2 data.tsv

# Extract fields from CSV
cut -d',' -f1,3 data.csv

# Extract first 10 characters of each line
cut -c1-10 file.txt

# Extract from character 5 to end
cut -c5- file.txt

# Extract multiple fields
cut -d':' -f1,3,5 /etc/passwd

# Change output delimiter
cut -d',' -f1,3 --output-delimiter=$'\t' data.csv

# Only print lines that contain the delimiter
cut -d',' -f2 -s data.csv

# Extract everything EXCEPT field 2
cut -d',' --complement -f2 data.csv

# Extract bytes (useful for fixed-width data)
cut -b1-8 fixed_width.txt

# Extract username and shell from /etc/passwd
cut -d: -f1,7 /etc/passwd

Gotchas

  • cut uses single-character delimiters only. You cannot use a multi-character string as a delimiter. For that, use awk.
  • Default delimiter is TAB, not space. For space-delimited data, use cut -d' ', but note that multiple consecutive spaces are NOT treated as one delimiter (use awk for that).
  • -f requires -d to be meaningful with non-TAB delimiters.
  • Without -s, lines without the delimiter are passed through unchanged. Add -s to skip them.
  • Fields are 1-indexed, not 0-indexed.
  • cut cannot reorder fields. cut -f3,1 outputs fields in their original order (1,3), not (3,1). Use awk to reorder.
Repository
flox/floxenvs
Last updated
Created

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.