GNU bug report logs - #81749
uniq does not document format for -c

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Reported by: Tim Landscheidt <tim@HIDDEN>; dated Sun, 30 Aug 2026 15:00:02 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 30 Aug 2026 14:59:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Aug 30 10:59:04 2026
Received: from localhost ([127.0.0.1]:41559 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1x0gzw-0006xG-HG
	for submit <at> debbugs.gnu.org; Sun, 30 Aug 2026 10:59:04 -0400
Received: from lists1p.gnu.org ([2001:470:142::17]:41708)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <tim@HIDDEN>)
 id 1x0gzt-0006wP-NT
 for submit <at> debbugs.gnu.org; Sun, 30 Aug 2026 10:59:02 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <tim@HIDDEN>)
 id 1x0gzm-00050n-QU
 for bug-coreutils@HIDDEN; Sun, 30 Aug 2026 10:58:54 -0400
Received: from gavdos.tim-landscheidt.de ([2a01:4f8:1c0c:4bd6::1])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <tim@HIDDEN>)
 id 1x0gzl-0001he-3C
 for bug-coreutils@HIDDEN; Sun, 30 Aug 2026 10:58:54 -0400
Received: from [2a02:8071:71c0:e660::f29c] (port=35764 helo=vagabond)
 by gavdos.tim-landscheidt.de with esmtpsa (TLS1.3) tls
 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96)
 (envelope-from <tim@HIDDEN>) id 1x0gzg-004lFN-33
 for bug-coreutils@HIDDEN; Sun, 30 Aug 2026 14:58:49 +0000
From: Tim Landscheidt <tim@HIDDEN>
To: bug-coreutils@HIDDEN
Subject: uniq does not document format for -c
Organization: https://www.tim-landscheidt.de/
Date: Sun, 30 Aug 2026 14:58:47 +0000
Message-ID: <87tsob7izc.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass client-ip=2a01:4f8:1c0c:4bd6::1;
 envelope-from=tim@HIDDEN; helo=gavdos.tim-landscheidt.de
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.1 (/)

uniq (GNU coreutils) 9.7's man page and "--help" output says
(on Fedora 43):

|   -c, --count           prefix lines by the number of occurrences

The info documentation says:

| =E2=80=98-c=E2=80=99
| =E2=80=98--count=E2=80=99
|      Print the number of times each line occurred along with the line.

None document that the count is separated from the line by a
space, and that the count is space-left-padded to seven
characters (uniq.c: "%7jd "), i. e.:

| $ seq -f '0%f' 1 1 100 | cut -c -1 | uniq -c
|     100 0
| $ seq -f '0%f' 1 1 1000000 | cut -c -1 | uniq -c
| 1000000 0
| $ seq -f '0%f' 1 1 10000000 | cut -c -1 | uniq -c
| 10000000 0
| $

So it would be nice if that format could be documented so
that it could be relied upon.

While looking into this, I noticed that POSIX
(https://pubs.opengroup.org/onlinepubs/9799919799/utilities/uniq.html)
defines the format as:

| If the -c option is specified, the output file shall be empty or each lin=
e shall be of the form:

| "%d %s", <number of duplicates>, <line>

On the other hand, in the Examples section, it uses the
format "%5d %s":

| This first example tests the line counting option, comparing
| each line of the input file data starting from the second
| field:

| uniq -c -f 1 uniq_0I.t
|     1 #01 foo0 bar0 foo1 bar1
|     1 #02 bar0 foo1 bar1 foo1
|     1 #03 foo0 bar0 foo1 bar1
|     1 #04
|     2 #05 foo0 bar0 foo1 bar1
|     1 #07 bar0 foo1 bar1 foo0

Obviously, this offers the chance to make "uniq -c" depend
on POSIXLY_CORRECT or POSIXLY_EXAMPLES_CORRECT and other
such shenanigans.

But it would probably be more useful for POSIX to redefine
the format to:

| "%*d %s", <minimum field width>, <number of duplicates>, <line>

and declare minimum field width to be
implementation-defined, but at least 1 (or something
similarly sensible).




Acknowledgement sent to Tim Landscheidt <tim@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#81749; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 30 Aug 2026 15:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.