cut — Extract sections (fields or characters) from each line across all 5 shells
Equivalents in every shell
Bashunix
cut -d',' -f1 file.csvZshunix
cut -d',' -f1 file.csvFishunix
cut -d',' -f1 file.csvPowerShellwindows
Get-Content file.csv | ForEach-Object { ($_ -split ',')[0] }For structured CSV, prefer `Import-Csv` and `Select-Object -ExpandProperty <Column>`.
Worked examples
Extract the second comma-separated field
Bash
cut -d',' -f2 file.csvPowerShell
Get-Content file.csv | ForEach-Object { ($_ -split ',')[1] }cmd.exe
for /f "tokens=2 delims=," %a in (file.csv) do @echo %aExtract characters 1–10 of each line
Bash
cut -c1-10 file.txtPowerShell
Get-Content file.txt | ForEach-Object { $_.Substring(0, [Math]::Min(10, $_.Length)) }Pick the user and shell columns from /etc/passwd
Bash
cut -d':' -f1,7 /etc/passwdPowerShell
Get-Content /etc/passwd | ForEach-Object { $f = $_ -split ':'; "$($f[0]):$($f[6])" }Gotchas
- cut field numbers are 1-indexed; PowerShell array indices are 0-based — subtract one when porting.
- cut’s `-d` accepts only a single character; for multi-char or regex delimiters use awk or PowerShell `-split`.
- If the delimiter is missing on a line, cut prints the whole line by default; PowerShell `-split` returns the line as element `[0]` and nothing else.
WSL & PowerShell Core notes
pwshpwsh has no `cut` cmdlet. The closest one-liner is `Get-Content file | ForEach-Object { ($_ -split 'delim')[N-1] }`; for structured delimited data, `Import-Csv -Delimiter ',' file | Select-Object -ExpandProperty Column` is far more robust because it handles quoted fields, embedded delimiters, and gives typed column access. On Linux/macOS pwsh 7+ hosts the system `cut` is on `$PATH` — shell out for very large files where the in-memory `-split` approach blows the heap.
WSLGNU `cut` has byte-mode (`-b`) and character-mode (`-c`); byte-mode is the historical default and silently breaks on multi-byte UTF-8 — `cut -c1-3` over `中文` can slice mid-codepoint. Use `-c` with `LC_ALL=C.UTF-8` (or your distro's UTF-8 locale) for grapheme-aware slicing on Linux distros that compile with locale awareness. On `/mnt/c/...` paths the per-line cost is negligible; the DrvFs read cost dominates, so copy huge Windows-side CSVs to `~/` before slicing repeatedly.