How to delete specific characters again?

QuestionsQuestions8 SkillsProDec, 17 2025
092

No problem at all! To delete specific characters using the tr command, you need to use the -d option.

The basic syntax is:

echo 'your_text' | tr -d 'characters_to_delete'

Let's use the example from the step again:

echo 'hello labex' | tr -d 'olh'

Here's what each part does:

  • echo 'hello labex': This prints the string "hello labex" to the standard output.
  • |: This is a pipe. It takes the output of the echo command and sends it as input to the tr command.
  • tr -d 'olh':
    • tr: The command itself.
    • -d: This option stands for "delete". It tells tr to remove any characters specified in the next argument.
    • 'olh': This is the set of characters that tr will search for in the input stream and delete. In this case, it will delete all occurrences of 'o', 'l', and 'h'.

When you run this command, the output will be e abex.

You can try it with different characters. For instance, if you wanted to delete all vowels from "hello labex":

echo 'hello labex' | tr -d 'aeiou'

Give it a try in the terminal! Let me know if you have any more questions.

0 Comments

no data
Be the first to share your comment!