Pregunta

I am having trouble understanding the -c option in tr (Unix command).

Looking at this format for tr: tr [Options] set1 [set2]

I understand that -c is an [option] available for tr which means that "it takes the complement of set1 ( aka, all characters not in set1). But, can someone please give an example of how to use this command and explain the benefits.

Thank you

¿Fue útil?

Solución

It means to complement the character range. When you complement the string A-Z you get Any character that is not in A ... Z.

Sometimes it is much easier to specify a task with the complement. Suppose you want to count the number of semicolons in a C source file. You delete all non-semicolons and count what's left:

tr -d -c \; < file.c | wc -c
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top