sort -u with -c, what does it do?
Clash 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
.
sort
add a comment |Â
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
.
sort
Related: unix.stackexchange.com/q/76049/117549
â Jeff Schaller
Oct 20 '17 at 10:36
add a comment |Â
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
.
sort
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
.
sort
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
.
add a comment |Â
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.
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Oct 20 '17 at 9:08
Stephen Kitt
144k22313378
144k22313378
add a comment |Â
add a comment |Â
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
.
add a comment |Â
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
.
add a comment |Â
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
.
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
.
edited Oct 20 '17 at 9:25
answered Oct 20 '17 at 9:12
Kusalananda
105k14209326
105k14209326
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited Oct 20 '17 at 9:20
answered Oct 20 '17 at 9:13
zeppelin
3,040416
3,040416
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%2f399304%2fsort-u-with-c-what-does-it-do%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
Related: unix.stackexchange.com/q/76049/117549
â Jeff Schaller
Oct 20 '17 at 10:36