문제

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

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top