tr — Translate or delete characters from input across all 5 shells
Equivalents in every shell
tr 'a-z' 'A-Z' < filetr 'a-z' 'A-Z' < filetr 'a-z' 'A-Z' < fileGet-Content file | ForEach-Object { $_.ToUpper() }No native tr; string methods and `-replace` cover the common transforms.
powershell -Command "Get-Content file | ForEach-Object { $_.ToUpper() }"cmd has no character-translation built-in.
Worked examples
Convert a file to uppercase
tr 'a-z' 'A-Z' < file.txtGet-Content file.txt | ForEach-Object { $_.ToUpper() }Strip carriage returns (CRLF → LF)
tr -d '\r' < dos.txt > unix.txt(Get-Content dos.txt -Raw) -replace "`r",'' | Set-Content unix.txt -NoNewlineSqueeze repeated spaces into one
tr -s ' ' < file.txtGet-Content file.txt | ForEach-Object { $_ -replace ' +',' ' }Gotchas
- tr operates on bytes, not characters — multi-byte UTF-8 ranges can be mangled when used with character classes.
- PowerShell `-replace` is regex; use `.Replace()` for literal string replacement instead.
- cmd has no built-in translation — even ROT13-style transforms require PowerShell or external tools.
WSL & PowerShell Core notes
Common tasks using tr
- Convert line endings between CRLF and LF
Strip or insert carriage returns to switch a file between Windows (CRLF, \r\n) and Unix (LF, \n) line endings.
- Find and replace text in files
Substitute one string for another inside a file (or every file in a tree), in place.
- Format text into aligned columns
Take tab- or whitespace-separated text and produce aligned columns — for human-readable tables, `mount` / `df` output reformatting, and CSV pretty-printing.
- Generate a random password
Produce a strong random password from the command line — cryptographic-quality, not `$RANDOM`.
- Generate a random string
Produce a fixed-length random ASCII string — useful for tokens, slugs, file suffixes, and test fixtures.
- Normalize whitespace in text
Collapse multiple spaces / tabs into single spaces and strip line-leading / trailing whitespace — for diff-friendly text, CSV cleanup, and config-file canonicalization.
- Strip ANSI color codes from output
Remove ESC[…m terminal color sequences from text — for clean log archives, machine-parseable output, and pasting to non-color-aware destinations.