Page MenuHomeFreeBSD

uniq(1): Allow -c to be used alongside -d or -u
ClosedPublic

Authored by kevans on May 12 2017, 5:40 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 26 2024, 11:38 AM
Unknown Object (File)
Oct 26 2024, 11:37 AM
Unknown Object (File)
Oct 26 2024, 11:37 AM
Unknown Object (File)
Oct 26 2024, 11:37 AM
Unknown Object (File)
Oct 26 2024, 11:22 AM
Unknown Object (File)
Oct 21 2024, 8:17 PM
Unknown Object (File)
Oct 2 2024, 4:06 PM
Unknown Object (File)
Sep 29 2024, 6:32 PM
Subscribers
None

Details

Summary

Bring in some bits from NetBSD and lift the restriction in uniq(1) that -c cannot be used with the -d and -u options. This restriction
seems unnecessary and is supported at least by GNU, OpenBSD, and NetBSD. Lift the restriction and simplify
the show() logic a little bit to maintain functionality when -c is provided with -d/-u.

Also with this change, -d and -u are now actually a mutually exclusive, albeit valid, combination. Given that they both indicate opposite behavior, uniq(1) will no longer output anything if both -d and -u are supplied. This is in line with NetBSD as well as GNU, and likely OpenBSD but this has not been checked.

Adjust the man page and usage() to reflect that -c is its own standalone option.

This is a partial revert of r98547.

PR: 200553

Test Plan

Run uniq(1) tests, exp-run?

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 9235
Build 9685: arc lint + arc unit

Event Timeline

kevans retitled this revision from uniq(1): Allow -c, -d, and -u combinations to uniq(1): Allow -c to be used alongside -d or -u.May 12 2017, 5:58 PM

I didn't explicitly mention it, but this does not change the default behavior in any way.

Before:

$ printf "A\nA\nB\nB\nC\n" > /tmp/test1
$ uniq /tmp/test1
A
B
C
$ uniq -c /tmp/test1
   2 A
   2 B
   1 C
$ uniq -cd /tmp/test1
usage...
$ uniq -cu /tmp/test1
usage...

After:

$ uniq /tmp/test1
A
B
C
$ uniq -c /tmp/test1
   2 A
   2 B
   1 C
$ uniq -cd /tmp/test1
   2 A
   2 B
$ uniq -cu /tmp/test1
   1 C

I've omitted the uniq -d and uniq -u results from before and after since they're trivial (in this case) and unchanged between the two versions.

  • Bring uniq(1) closer inline with NetBSD w.r.t. -c/-d/-u handling

This should probably require an exp-run since -du is no longer a combination that will produce
the same output as if no flags were passed to uniq(1). On the other hand, FreeBSD's
uniq(1) was the only that I know of that actually handled -du in this somewhat
bizarre manner, so there will likely be no fallout.

Obtained from: NetBSD (no specific commit)

kevans edited the test plan for this revision. (Show Details)

To confirm, uniq -cu should be all those lines which have a -c count of 1, and uniq -du should be all those lines which have a -c count greater than one?

Also, should it be an error to specify both -d and -u?

To confirm, uniq -cu should be all those lines which have a -c count of 1, and uniq -du should be all those lines which have a -c count greater than one?

-cu are those with a -c count of 1, -cd are those with a -c count greater than one.

Also, should it be an error to specify both -d and -u?

I would think so, but no one else seems to go to these lengths and instead just lets -d and -u slip by and result in no matches since they imply conflicting conditions.

In D10694#222398, @kevans91_ksu.edu wrote:

-cu are those with a -c count of 1, -cd are those with a -c count greater than one.

Sigh, I indeed meant to type -cu and -cd. Thanks.

Also, should it be an error to specify both -d and -u?

I would think so, but no one else seems to go to these lengths and instead just lets -d and -u slip by and result in no matches since they imply conflicting conditions.

Ok.

This revision is now accepted and ready to land.May 15 2017, 3:49 PM
This revision was automatically updated to reflect the committed changes.