I cannot understand what -c parameter does in tr command in Ubuntu GNU/Linux even though I read the manual

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question

















  • 1




    en.wikipedia.org/wiki/Complement_(set_theory)
    – steeldriver
    Jun 6 at 11:37














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?







share|improve this question

















  • 1




    en.wikipedia.org/wiki/Complement_(set_theory)
    – steeldriver
    Jun 6 at 11:37












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?







share|improve this question













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?









share|improve this question












share|improve this question




share|improve this question








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












  • 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










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.






share|improve this answer























    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    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






























    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.






    share|improve this answer



























      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.






      share|improve this answer

























        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.






        share|improve this answer















        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.







        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jun 6 at 12:50


























        answered Jun 6 at 11:38









        Stephen Kitt

        140k22302363




        140k22302363






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?