Skip to content
shellmap

trTranslate or delete characters from input across all 5 shells

Equivalents in every shell

Bashunix
tr 'a-z' 'A-Z' < file
Zshunix
tr 'a-z' 'A-Z' < file
Fishunix
tr 'a-z' 'A-Z' < file
PowerShellwindows
Get-Content file | ForEach-Object { $_.ToUpper() }

No native tr; string methods and `-replace` cover the common transforms.

cmd.exewindows
powershell -Command "Get-Content file | ForEach-Object { $_.ToUpper() }"

cmd has no character-translation built-in.

Worked examples

Convert a file to uppercase

Bash
tr 'a-z' 'A-Z' < file.txt
PowerShell
Get-Content file.txt | ForEach-Object { $_.ToUpper() }

Strip carriage returns (CRLF → LF)

Bash
tr -d '\r' < dos.txt > unix.txt
PowerShell
(Get-Content dos.txt -Raw) -replace "`r",'' | Set-Content unix.txt -NoNewline

Squeeze repeated spaces into one

Bash
tr -s ' ' < file.txt
PowerShell
Get-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

pwsh`tr` is not part of pwsh — the bash idiom `tr -d '\r'` for stripping CRLF has no direct cmdlet. On every pwsh platform, use `(Get-Content file -Raw) -replace "`r", "" | Set-Content file -NoNewline` instead. Beware: `Set-Content` defaults to UTF-16 LE on Windows PowerShell 5.1 and UTF-8 (no BOM) on pwsh 7+ — pass `-Encoding utf8` explicitly for portable scripts.
WSLLine-ending stripping is the #1 WSL `tr` use case: files created in Windows-side editors (Notepad, default `code` save without LF normalization) ship CRLF, and Linux tools (`bash`, `make`, `python` strict mode) break on the `\r`. `tr -d '\r' < windows.sh > unix.sh` or in-place `sed -i 's/\r$//' file` are the canonical fixes. For repeated work, configure your editor to save LF on `*.sh` (`.editorconfig`: `end_of_line = lf`) so the conversion isn't needed.

Common tasks using tr

Related commands