Reputation: 2975
Why is sort -c
output not being redirected to file temp.txt
?
If I remove -c
, it does redirect, as seen below:
$ cat numericSort
33:Thirty Three:6
11:Eleven:2
45:Forty Five:9
01:Zero One:1
99:Ninety Nine:9
18:Eighteen:01
56:Fifty Six:4
78:Seventy Eight:2
$ sort numericSort > temp.txt
$ cat temp.txt
01:Zero One:1
11:Eleven:2
18:Eighteen:01
33:Thirty Three:6
45:Forty Five:9
56:Fifty Six:4
78:Seventy Eight:2
99:Ninety Nine:9
$ rm temp.txt
$ sort -c numericSort > temp.txt
sort: numericSort:2: disorder: 11:Eleven:2
$ cat temp.txt
# No Output Here
Upvotes: 0
Views: 78
Reputation: 77896
Based on document of sort
command
-c, --check, --check=diagnose-first
check for sorted input; do not sort
Check whether the given files are already sorted: if they are not all sorted, print an error message and exit with a status of 1.
so your command sort -c numericSort > temp.txt
is essentially just checking whether the file numericSort
is sorted or not. If not sorted print error on STDERR
and hence you don't see any output to temp.txt
. Probably you want to redirect STDERR instead like
sort -c numericSort 2> temp.txt
Upvotes: 3
Reputation: 12287
The output of sort -c
goes to stderr
, not stdout
.
If you want to redirect that instead:
$ sort -c numericSort 2> temp.txt
Upvotes: 4