sort -u with -c, what does it do?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












The man page for sort’s -u option says:




with -c, check for strict ordering;
without -c, output only the first of an equal run




Can someone translate this into basic English for me? The -uc option gives me the same output as only -c.







share|improve this question






















  • Related: unix.stackexchange.com/q/76049/117549
    – Jeff Schaller
    Oct 20 '17 at 10:36














up vote
2
down vote

favorite












The man page for sort’s -u option says:




with -c, check for strict ordering;
without -c, output only the first of an equal run




Can someone translate this into basic English for me? The -uc option gives me the same output as only -c.







share|improve this question






















  • Related: unix.stackexchange.com/q/76049/117549
    – Jeff Schaller
    Oct 20 '17 at 10:36












up vote
2
down vote

favorite









up vote
2
down vote

favorite











The man page for sort’s -u option says:




with -c, check for strict ordering;
without -c, output only the first of an equal run




Can someone translate this into basic English for me? The -uc option gives me the same output as only -c.







share|improve this question














The man page for sort’s -u option says:




with -c, check for strict ordering;
without -c, output only the first of an equal run




Can someone translate this into basic English for me? The -uc option gives me the same output as only -c.









share|improve this question













share|improve this question




share|improve this question








edited Oct 20 '17 at 9:43









Kusalananda

105k14209326




105k14209326










asked Oct 20 '17 at 9:01









Lumify

1217




1217











  • Related: unix.stackexchange.com/q/76049/117549
    – Jeff Schaller
    Oct 20 '17 at 10:36
















  • Related: unix.stackexchange.com/q/76049/117549
    – Jeff Schaller
    Oct 20 '17 at 10:36















Related: unix.stackexchange.com/q/76049/117549
– Jeff Schaller
Oct 20 '17 at 10:36




Related: unix.stackexchange.com/q/76049/117549
– Jeff Schaller
Oct 20 '17 at 10:36










3 Answers
3






active

oldest

votes

















up vote
3
down vote













Strict ordering means that no value can be repeated. Compare the output of



printf "%sn" 1 2 3 4 4 | sort -uc


with that of



printf "%sn" 1 2 3 4 4 | sort -c





share|improve this answer



























    up vote
    2
    down vote













    The -c option to sort causes sort to check whether the input data is sorted correctly, taking any other options into account. It will not perform any sorting. In some implementations of sort, -c may be written --check.



    So sort -u -c would perform a check on the data and let you know whether the data is sorted and contains any duplicate entries. If it is sorted and contains no duplicate entries it won't say anything, but if there are duplicate entries or if the data is unsorted, it will produce a diagnostic message and exit with a non-zero exit status.



    You may used this in the following way:



    if sort -uC file; then
    echo 'file is sorted and contains no duplicate entries'
    else
    echo 'file is unsorted or contains duplicate entries'
    fi


    The -C option does the same thing as -c but stops sort from producing any output. -C may sometimes be written --check=quiet or --check=silent.






    share|improve this answer





























      up vote
      1
      down vote













      Here is how the extended sort manual (info coreutils 'sort invocation') explains it:




      ‘--unique’



      Normally, output only the first of a sequence of lines that compare equal. For the --check (-c or -C) option, check that no pair of consecutive lines compares equal.




      I.e. combining -c (check) with -u (unique) will, quite logically, check that there is no duplicates in the input.



      For example:



      %echo -e "ananbnc"| sort -c && echo OK
      OK

      %echo -e "ananbnc"| sort -uc && echo OK
      sort: -:2: disorder: a


      While the input is sorted (a->a->b->c), there are duplicates, so -uc will fail.






      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%2f399304%2fsort-u-with-c-what-does-it-do%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        3
        down vote













        Strict ordering means that no value can be repeated. Compare the output of



        printf "%sn" 1 2 3 4 4 | sort -uc


        with that of



        printf "%sn" 1 2 3 4 4 | sort -c





        share|improve this answer
























          up vote
          3
          down vote













          Strict ordering means that no value can be repeated. Compare the output of



          printf "%sn" 1 2 3 4 4 | sort -uc


          with that of



          printf "%sn" 1 2 3 4 4 | sort -c





          share|improve this answer






















            up vote
            3
            down vote










            up vote
            3
            down vote









            Strict ordering means that no value can be repeated. Compare the output of



            printf "%sn" 1 2 3 4 4 | sort -uc


            with that of



            printf "%sn" 1 2 3 4 4 | sort -c





            share|improve this answer












            Strict ordering means that no value can be repeated. Compare the output of



            printf "%sn" 1 2 3 4 4 | sort -uc


            with that of



            printf "%sn" 1 2 3 4 4 | sort -c






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 20 '17 at 9:08









            Stephen Kitt

            144k22313378




            144k22313378






















                up vote
                2
                down vote













                The -c option to sort causes sort to check whether the input data is sorted correctly, taking any other options into account. It will not perform any sorting. In some implementations of sort, -c may be written --check.



                So sort -u -c would perform a check on the data and let you know whether the data is sorted and contains any duplicate entries. If it is sorted and contains no duplicate entries it won't say anything, but if there are duplicate entries or if the data is unsorted, it will produce a diagnostic message and exit with a non-zero exit status.



                You may used this in the following way:



                if sort -uC file; then
                echo 'file is sorted and contains no duplicate entries'
                else
                echo 'file is unsorted or contains duplicate entries'
                fi


                The -C option does the same thing as -c but stops sort from producing any output. -C may sometimes be written --check=quiet or --check=silent.






                share|improve this answer


























                  up vote
                  2
                  down vote













                  The -c option to sort causes sort to check whether the input data is sorted correctly, taking any other options into account. It will not perform any sorting. In some implementations of sort, -c may be written --check.



                  So sort -u -c would perform a check on the data and let you know whether the data is sorted and contains any duplicate entries. If it is sorted and contains no duplicate entries it won't say anything, but if there are duplicate entries or if the data is unsorted, it will produce a diagnostic message and exit with a non-zero exit status.



                  You may used this in the following way:



                  if sort -uC file; then
                  echo 'file is sorted and contains no duplicate entries'
                  else
                  echo 'file is unsorted or contains duplicate entries'
                  fi


                  The -C option does the same thing as -c but stops sort from producing any output. -C may sometimes be written --check=quiet or --check=silent.






                  share|improve this answer
























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    The -c option to sort causes sort to check whether the input data is sorted correctly, taking any other options into account. It will not perform any sorting. In some implementations of sort, -c may be written --check.



                    So sort -u -c would perform a check on the data and let you know whether the data is sorted and contains any duplicate entries. If it is sorted and contains no duplicate entries it won't say anything, but if there are duplicate entries or if the data is unsorted, it will produce a diagnostic message and exit with a non-zero exit status.



                    You may used this in the following way:



                    if sort -uC file; then
                    echo 'file is sorted and contains no duplicate entries'
                    else
                    echo 'file is unsorted or contains duplicate entries'
                    fi


                    The -C option does the same thing as -c but stops sort from producing any output. -C may sometimes be written --check=quiet or --check=silent.






                    share|improve this answer














                    The -c option to sort causes sort to check whether the input data is sorted correctly, taking any other options into account. It will not perform any sorting. In some implementations of sort, -c may be written --check.



                    So sort -u -c would perform a check on the data and let you know whether the data is sorted and contains any duplicate entries. If it is sorted and contains no duplicate entries it won't say anything, but if there are duplicate entries or if the data is unsorted, it will produce a diagnostic message and exit with a non-zero exit status.



                    You may used this in the following way:



                    if sort -uC file; then
                    echo 'file is sorted and contains no duplicate entries'
                    else
                    echo 'file is unsorted or contains duplicate entries'
                    fi


                    The -C option does the same thing as -c but stops sort from producing any output. -C may sometimes be written --check=quiet or --check=silent.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 20 '17 at 9:25

























                    answered Oct 20 '17 at 9:12









                    Kusalananda

                    105k14209326




                    105k14209326




















                        up vote
                        1
                        down vote













                        Here is how the extended sort manual (info coreutils 'sort invocation') explains it:




                        ‘--unique’



                        Normally, output only the first of a sequence of lines that compare equal. For the --check (-c or -C) option, check that no pair of consecutive lines compares equal.




                        I.e. combining -c (check) with -u (unique) will, quite logically, check that there is no duplicates in the input.



                        For example:



                        %echo -e "ananbnc"| sort -c && echo OK
                        OK

                        %echo -e "ananbnc"| sort -uc && echo OK
                        sort: -:2: disorder: a


                        While the input is sorted (a->a->b->c), there are duplicates, so -uc will fail.






                        share|improve this answer


























                          up vote
                          1
                          down vote













                          Here is how the extended sort manual (info coreutils 'sort invocation') explains it:




                          ‘--unique’



                          Normally, output only the first of a sequence of lines that compare equal. For the --check (-c or -C) option, check that no pair of consecutive lines compares equal.




                          I.e. combining -c (check) with -u (unique) will, quite logically, check that there is no duplicates in the input.



                          For example:



                          %echo -e "ananbnc"| sort -c && echo OK
                          OK

                          %echo -e "ananbnc"| sort -uc && echo OK
                          sort: -:2: disorder: a


                          While the input is sorted (a->a->b->c), there are duplicates, so -uc will fail.






                          share|improve this answer
























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            Here is how the extended sort manual (info coreutils 'sort invocation') explains it:




                            ‘--unique’



                            Normally, output only the first of a sequence of lines that compare equal. For the --check (-c or -C) option, check that no pair of consecutive lines compares equal.




                            I.e. combining -c (check) with -u (unique) will, quite logically, check that there is no duplicates in the input.



                            For example:



                            %echo -e "ananbnc"| sort -c && echo OK
                            OK

                            %echo -e "ananbnc"| sort -uc && echo OK
                            sort: -:2: disorder: a


                            While the input is sorted (a->a->b->c), there are duplicates, so -uc will fail.






                            share|improve this answer














                            Here is how the extended sort manual (info coreutils 'sort invocation') explains it:




                            ‘--unique’



                            Normally, output only the first of a sequence of lines that compare equal. For the --check (-c or -C) option, check that no pair of consecutive lines compares equal.




                            I.e. combining -c (check) with -u (unique) will, quite logically, check that there is no duplicates in the input.



                            For example:



                            %echo -e "ananbnc"| sort -c && echo OK
                            OK

                            %echo -e "ananbnc"| sort -uc && echo OK
                            sort: -:2: disorder: a


                            While the input is sorted (a->a->b->c), there are duplicates, so -uc will fail.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Oct 20 '17 at 9:20

























                            answered Oct 20 '17 at 9:13









                            zeppelin

                            3,040416




                            3,040416



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399304%2fsort-u-with-c-what-does-it-do%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?