Remove Punctuation With Linux tr

Clean up transcripts, labels, and file lists using the Linux tr command. Learn how to remove punctuation from text without installing new tools.

Before you start

The tr utility is included with core Linux utilities, so there is nothing to install. It works on a local file or text that you pipe into the command; it does not upload content to a service. Work on a copy of the file if you want to keep the original wording unchanged.

tr treats characters literally, not as regular expressions. Decide which punctuation should be removed, because a bracket, quote, or symbol must be listed in the set. A dot outside a bracket can look like a wildcard to some tools, but tr handles it as the dot character.

Step-by-step instructions

First, open a terminal in the folder that contains the file. To remove a fixed list of punctuation from input.txt and write the result to output.txt, use a command in this form:

tr -d '.,;:!?"()[]{}' < input.txt > output.txt

The -d option tells tr to delete every character that matches the set. Keep the quote characters at the end of the set to avoid confusion when the shell interprets the argument.

If the text is already in a command line or pipeline, skip the input redirect and pipe it into tr. For a subtitle or transcript file, the command keeps letters, digits, spaces, and newlines unless those characters are added to the delete set.

Check the output

Open output.txt and look at places where punctuation was removed. tr does not add spaces, so two words may become joined when a comma or period is removed. This is most visible in dense text such as timestamps, captions, or filenames.

The output should be plain text with the original line breaks intact. tr only changes the characters in the delete set, so numbers, accented letters, and whitespace remain unless they are included in the set.

Common problems and next steps

If a dash is being removed unexpectedly, check whether the set contains a range. tr treats a hyphen between two other characters as a range specifier, so place - at the end of the set to treat it as a literal hyphen.

Use a character class for a broader cleanup. The command tr -d '[:punct:]' < input.txt > output.txt removes punctuation according to the current locale, but the result can vary depending on the system's locale settings.

To remove spaces and punctuation together, include the space character and any whitespace forms you need in the set. Replace rather than delete when a separator is required, using a pair of sets in the form tr ',' ' ' < input.txt > output.txt to turn commas into spaces.