sort -rn produces output different from gnusort
Open
Nobody has claimed this yet.
U - sort
- Dominant language
- Rust
- Stars
- 24.1k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 365
Description
I have a file with the following content:
$ cat /tmp/sveta
1 lock/lock0lock.c line 5163
1 lock/lock0lock.c line 3249
1 fsp/fsp0fsp.c line 3395
1 btr/btr0cur.c line 672
1 btr/btr0cur.c line 450
1 ./include/btr0btr.ic line 53
If I run gnusort on my file, I get the following results (expected):
$ gnusort -r /tmp/sveta
1 lock/lock0lock.c line 5163
1 lock/lock0lock.c line 3249
1 ./include/btr0btr.ic line 53
1 fsp/fsp0fsp.c line 3395
1 btr/btr0cur.c line 672
1 btr/btr0cur.c line 450
With sort -nr I get a different order (pay attention for the last line):
$ sort -nr /tmp/sveta
1 lock/lock0lock.c line 5163
1 lock/lock0lock.c line 3249
1 fsp/fsp0fsp.c line 3395
1 btr/btr0cur.c line 672
1 btr/btr0cur.c line 450
1 ./include/btr0btr.ic line 53
However, if I use pipe sort -n | sort -r, the results are the same as with gnusort:
$ sort -n /tmp/sveta | sort -r
1 lock/lock0lock.c line 5163
1 lock/lock0lock.c line 3249
1 ./include/btr0btr.ic line 53
1 fsp/fsp0fsp.c line 3395
1 btr/btr0cur.c line 672
1 btr/btr0cur.c line 450
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided /tmp/sveta input and compare sort -nr with sort -n | sort -r and GNU sort. Trace the sort command's handling of combined numeric and reverse flags, then verify that the output ordering matches GNU sort and add a regression test for this input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100