I cannot understand what -c parameter does in tr command in Ubuntu GNU/Linux even though I read the manual
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I try to understand what -c
option does in tr
command according to man tr
command it says:
-c, -C, --complement
use the complement of SET1
But I cannot understad what the doc mean by "complement" so I did the following example to understand it:
I created the following file named trance.txt
:
ILOVE YOU
I HATE YOU
i WANNA EAT APPLE PIE
And I run: tr -C A-Za-z "n" < trance.txt
That gives the output:
ILOVE
YOU
I
HATE
YOU
i
WANNA
EAT
APPLE
PIE
But I still do not get it what actually -c
option does. Can you explain to me please?
tr
add a comment |Â
up vote
1
down vote
favorite
I try to understand what -c
option does in tr
command according to man tr
command it says:
-c, -C, --complement
use the complement of SET1
But I cannot understad what the doc mean by "complement" so I did the following example to understand it:
I created the following file named trance.txt
:
ILOVE YOU
I HATE YOU
i WANNA EAT APPLE PIE
And I run: tr -C A-Za-z "n" < trance.txt
That gives the output:
ILOVE
YOU
I
HATE
YOU
i
WANNA
EAT
APPLE
PIE
But I still do not get it what actually -c
option does. Can you explain to me please?
tr
1
en.wikipedia.org/wiki/Complement_(set_theory)
â steeldriver
Jun 6 at 11:37
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I try to understand what -c
option does in tr
command according to man tr
command it says:
-c, -C, --complement
use the complement of SET1
But I cannot understad what the doc mean by "complement" so I did the following example to understand it:
I created the following file named trance.txt
:
ILOVE YOU
I HATE YOU
i WANNA EAT APPLE PIE
And I run: tr -C A-Za-z "n" < trance.txt
That gives the output:
ILOVE
YOU
I
HATE
YOU
i
WANNA
EAT
APPLE
PIE
But I still do not get it what actually -c
option does. Can you explain to me please?
tr
I try to understand what -c
option does in tr
command according to man tr
command it says:
-c, -C, --complement
use the complement of SET1
But I cannot understad what the doc mean by "complement" so I did the following example to understand it:
I created the following file named trance.txt
:
ILOVE YOU
I HATE YOU
i WANNA EAT APPLE PIE
And I run: tr -C A-Za-z "n" < trance.txt
That gives the output:
ILOVE
YOU
I
HATE
YOU
i
WANNA
EAT
APPLE
PIE
But I still do not get it what actually -c
option does. Can you explain to me please?
tr
edited Jun 6 at 13:02
asked Jun 6 at 11:25
Dimitrios Desyllas
1599
1599
1
en.wikipedia.org/wiki/Complement_(set_theory)
â steeldriver
Jun 6 at 11:37
add a comment |Â
1
en.wikipedia.org/wiki/Complement_(set_theory)
â steeldriver
Jun 6 at 11:37
1
1
en.wikipedia.org/wiki/Complement_(set_theory)
â steeldriver
Jun 6 at 11:37
en.wikipedia.org/wiki/Complement_(set_theory)
â steeldriver
Jun 6 at 11:37
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
It replaces the set A-Za-z
with its complement, i.e. all the characters in the current character set, minus those specified. Quoting POSIX, in the absence of -d
:
If the -C option is specified, the complements of the characters specified by string1 (the set of all characters in the current character set, as defined by the current setting of LC_CTYPE, except for those actually specified in the string1 operand) shall be placed in the array in ascending collation sequence, as defined by the current setting of LC_COLLATE.
If the -c option is specified, the complement of the values specified by string1 shall be placed in the array in ascending order by binary value.
So your command is replacing all characters which arenâÂÂt A-Z or a-z with newlines.
Because tr
uses a one-to-one character map for its replacements, itâÂÂs not quite as simple as that; the -c
and -C
arenâÂÂt just âÂÂnot inâ options, they build the set of all characters which arenâÂÂt in the given set, in the order specified by the option. This is only relevant if the target set has more than one character.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
It replaces the set A-Za-z
with its complement, i.e. all the characters in the current character set, minus those specified. Quoting POSIX, in the absence of -d
:
If the -C option is specified, the complements of the characters specified by string1 (the set of all characters in the current character set, as defined by the current setting of LC_CTYPE, except for those actually specified in the string1 operand) shall be placed in the array in ascending collation sequence, as defined by the current setting of LC_COLLATE.
If the -c option is specified, the complement of the values specified by string1 shall be placed in the array in ascending order by binary value.
So your command is replacing all characters which arenâÂÂt A-Z or a-z with newlines.
Because tr
uses a one-to-one character map for its replacements, itâÂÂs not quite as simple as that; the -c
and -C
arenâÂÂt just âÂÂnot inâ options, they build the set of all characters which arenâÂÂt in the given set, in the order specified by the option. This is only relevant if the target set has more than one character.
add a comment |Â
up vote
4
down vote
accepted
It replaces the set A-Za-z
with its complement, i.e. all the characters in the current character set, minus those specified. Quoting POSIX, in the absence of -d
:
If the -C option is specified, the complements of the characters specified by string1 (the set of all characters in the current character set, as defined by the current setting of LC_CTYPE, except for those actually specified in the string1 operand) shall be placed in the array in ascending collation sequence, as defined by the current setting of LC_COLLATE.
If the -c option is specified, the complement of the values specified by string1 shall be placed in the array in ascending order by binary value.
So your command is replacing all characters which arenâÂÂt A-Z or a-z with newlines.
Because tr
uses a one-to-one character map for its replacements, itâÂÂs not quite as simple as that; the -c
and -C
arenâÂÂt just âÂÂnot inâ options, they build the set of all characters which arenâÂÂt in the given set, in the order specified by the option. This is only relevant if the target set has more than one character.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
It replaces the set A-Za-z
with its complement, i.e. all the characters in the current character set, minus those specified. Quoting POSIX, in the absence of -d
:
If the -C option is specified, the complements of the characters specified by string1 (the set of all characters in the current character set, as defined by the current setting of LC_CTYPE, except for those actually specified in the string1 operand) shall be placed in the array in ascending collation sequence, as defined by the current setting of LC_COLLATE.
If the -c option is specified, the complement of the values specified by string1 shall be placed in the array in ascending order by binary value.
So your command is replacing all characters which arenâÂÂt A-Z or a-z with newlines.
Because tr
uses a one-to-one character map for its replacements, itâÂÂs not quite as simple as that; the -c
and -C
arenâÂÂt just âÂÂnot inâ options, they build the set of all characters which arenâÂÂt in the given set, in the order specified by the option. This is only relevant if the target set has more than one character.
It replaces the set A-Za-z
with its complement, i.e. all the characters in the current character set, minus those specified. Quoting POSIX, in the absence of -d
:
If the -C option is specified, the complements of the characters specified by string1 (the set of all characters in the current character set, as defined by the current setting of LC_CTYPE, except for those actually specified in the string1 operand) shall be placed in the array in ascending collation sequence, as defined by the current setting of LC_COLLATE.
If the -c option is specified, the complement of the values specified by string1 shall be placed in the array in ascending order by binary value.
So your command is replacing all characters which arenâÂÂt A-Z or a-z with newlines.
Because tr
uses a one-to-one character map for its replacements, itâÂÂs not quite as simple as that; the -c
and -C
arenâÂÂt just âÂÂnot inâ options, they build the set of all characters which arenâÂÂt in the given set, in the order specified by the option. This is only relevant if the target set has more than one character.
edited Jun 6 at 12:50
answered Jun 6 at 11:38
Stephen Kitt
140k22302363
140k22302363
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f448166%2fi-cannot-understand-what-c-parameter-does-in-tr-command-in-ubuntu-gnu-linux-eve%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
en.wikipedia.org/wiki/Complement_(set_theory)
â steeldriver
Jun 6 at 11:37