How can the 'tr' command be used to delete specific characters from a string?

QuestionsQuestions4 SkillsProSimple Text ProcessingNov, 08 2025
096

The tr command can be used to delete specific characters from a string by using the -d option followed by the characters you want to remove. Here’s the syntax:

tr -d 'characters_to_delete' < input_file

If you want to delete characters directly from a string, you can use echo in combination with tr. For example, to delete digits and punctuation (like colons, commas, and semicolons) from a string, you can use:

echo 'Hello, World! 1234: Test;' | tr -d '0-9:,;'

This command will output:

Hello World! Test

In this example, all digits and the specified punctuation characters are removed from the input string.

0 Comments

no data
Be the first to share your comment!