[Bug 275764] `uniq -D -c` gives wrong values of repeat counts

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 14 Dec 2023 15:23:00 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=275764

            Bug ID: 275764
           Summary: `uniq -D -c` gives wrong values of repeat counts
           Product: Base System
           Version: 13.2-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: s110062131@m110.nthu.edu.tw
                CC: lwhsu@FreeBSD.org

## Environment:
* FreeBSD 13.2-RELEASE
* RPi 400 (bootloader 8ba17717 2023/01/11)
* GENET version 5.0 phy 0x0000

## Bug description:
```$ uniq -D -c``` gives wrong values of repeat counts.

## Steps to reproduce:
1. Assuming a file named animals.txt with the following content:

        alligator
        bear
        bear
        camel
        camel
        camel
        dolphin
        elephant
        bear
        fish
        fish
        bird
        lion
        koala
        koala
        koala
2. The following command should print all duplicated lines and repeat counts:
```
$ uniq -D -c animals.txt
```

## Actual result:
```
$ uniq -D -c animals.txt
   1 bear
   1 bear
   1 camel
   1 camel
   2 camel
   1 fish
   1 fish
   1 koala
   1 koala
```
As you can tell, repeat counts are wrong.

## Expected result:
```
$ uniq -D -c animals.txt
   1 bear
   2 bear
   1 camel
   2 camel
   3 camel
   1 fish
   2 fish
   1 koala
   2 koala
```
In fact, we actually tested it out on Linux as well. 
```
(Linux)
$ uniq -D -c animals.txt
uniq: printing all duplicated lines and repeat counts is meaningless
Try 'uniq --help' for more information.
```
We think it might be another acceptable way to handle this bug.

-- 
You are receiving this mail because:
You are the assignee for the bug.