Windows
Linux
Text Processing
Windows for /f (field parsing) equivalent in Linux
Cuts out sections of each line — by delimiter-separated field number or character position.
Windows
→
for /f (field parsing)
Linux equivalents
cut
cut
cut
Overview
What this command does
Cuts out sections of each line — by delimiter-separated field number or character position.
Migration tip:
cut -d ',' -f 2 extracts the second column of a CSV. For more complex field extraction, awk is more powerful and handles edge cases better.Practical tasks
Common use cases
Extract columns or fields from text
Cuts out sections of each line — by delimiter-separated field number or character position.
cut -d ',' -f 1
First CSV field
cut -d ':' -f 1
First colon-separated field
cut -c 1-10
First 10 characters of each line
Ready to run
Copyable Linux commands
Review paths, device names, package names and permissions before running any command.
cut -d ':' -f 1 /etc/passwd
cut -d ',' -f 2 data.csv
cut -d ' ' -f 1 /var/log/nginx/access.log
Walkthrough
Examples with explanations
# No direct Windows CMD equivalent
# Extract usernames from /etc/passwd:
cut -d ':' -f 1 /etc/passwd
# Extract second column from CSV:
cut -d ',' -f 2 data.csv
# Extract IPs from log (column 1):
cut -d ' ' -f 1 /var/log/nginx/access.log
Reference
Common options and variations
| Command or option | Use |
|---|---|
cut -d ',' -f 1 | First CSV field |
cut -d ':' -f 1 | First colon-separated field |
cut -c 1-10 | First 10 characters of each line |
cut -d ' ' -f 2-4 | Fields 2 through 4 |
cut -d '\t' -f 3 | Third tab-separated field |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
This command is the same on Debian/Ubuntu, Fedora and Arch Linux when the relevant tool is installed.
| Distribution | Package manager / base | Equivalent command | Difference to notice |
|---|---|---|---|
| Debian/Ubuntu | same command | cut |
Same command on this distribution. |
| Fedora | same command | cut |
Same command on this distribution. |
| Arch | same command | cut |
Same command on this distribution. |
Keep learning