How to Use the cut Command to Extract Text Columns in Linux
This guide explains how to use the Unix cut command to extract specific columns or character ranges from files or streams, detailing the -d, -f, and -c options with clear examples such as selecting fields from colon‑separated data.
cut
Overview
Extract text columns from a file or stream.
Syntax
cut -d'delimiter' -f fields # for specific delimiter
cut -c column_range # for fixed-width aligned dataOptions and parameters:
-d: specify delimiter, used with -f.
-f: select fields based on delimiter defined by -d.
-c: select character positions.
Examples
Create a file 1.txt with the following content: zhangsi:28:football:basketball:music:sing Extract the third field (football) using colon as delimiter: cut -d ':' -f 3 1.txt Extract the third and fifth fields (football and music): cut -d ':' -f 3,5 1.txt Extract from the third field to the end: cut -d ':' -f 3- 1.txt Extract fields three through five: cut -d ':' -f 3-5 1.txt Extract fields three through five and also the seventh field: cut -d ':' -f 3-5,7 1.txt Character‑based extraction example:
who | cut -c 3Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ZhiKe AI
We dissect AI-era technologies, tools, and trends with a hardcore perspective. Focused on large models, agents, MCP, function calling, and hands‑on AI development. No fluff, no hype—only actionable insights, source code, and practical ideas. Get a daily dose of intelligence to simplify tech and make efficiency tangible.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
