summaryrefslogtreecommitdiff
path: root/usr.bin/uniq
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-05-02 01:17:08 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-05-02 01:17:08 +0000
commita597327b9040542182760547def3242062aec440 (patch)
tree539a3696f97f889564b736d035a195454d1bede3 /usr.bin/uniq
parentad4e78b50a80361e164ee6885b6107692ba44463 (diff)
downloadsrc-test-a597327b9040542182760547def3242062aec440.tar.gz
src-test-a597327b9040542182760547def3242062aec440.zip
uniq(1): Add some long options
These match GNU uniq(1) where appropriate for compatibility's sake. While here, re-sort options alphabetically by the short-option. MFC after: 1 month
Notes
Notes: svn path=/head/; revision=333156
Diffstat (limited to 'usr.bin/uniq')
-rw-r--r--usr.bin/uniq/uniq.118
-rw-r--r--usr.bin/uniq/uniq.c15
2 files changed, 23 insertions, 10 deletions
diff --git a/usr.bin/uniq/uniq.1 b/usr.bin/uniq/uniq.1
index 969384097fb22..9fa37ef8b8ef3 100644
--- a/usr.bin/uniq/uniq.1
+++ b/usr.bin/uniq/uniq.1
@@ -31,7 +31,7 @@
.\" From: @(#)uniq.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd May 15, 2017
+.Dd May 1, 2018
.Dt UNIQ 1
.Os
.Sh NAME
@@ -71,34 +71,34 @@ so it may be necessary to sort the files first.
.Pp
The following options are available:
.Bl -tag -width Ds
-.It Fl c
+.It Fl c , Fl -count
Precede each output line with the count of the number of times the line
occurred in the input, followed by a single space.
-.It Fl d
+.It Fl d , Fl -repeated
Only output lines that are repeated in the input.
-.It Fl f Ar num
+.It Fl f Ar num , Fl -skip-fields Ar num
Ignore the first
.Ar num
fields in each input line when doing comparisons.
A field is a string of non-blank characters separated from adjacent fields
by blanks.
Field numbers are one based, i.e., the first field is field one.
-.It Fl s Ar chars
+.It Fl i , Fl -ignore-case
+Case insensitive comparison of lines.
+.It Fl s Ar chars , Fl -skip-chars Ar chars
Ignore the first
.Ar chars
characters in each input line when doing comparisons.
If specified in conjunction with the
-.Fl f
+.Fl f , Fl -unique
option, the first
.Ar chars
characters after the first
.Ar num
fields will be ignored.
Character numbers are one based, i.e., the first character is character one.
-.It Fl u
+.It Fl u , Fl -unique
Only output lines that are not repeated in the input.
-.It Fl i
-Case insensitive comparison of lines.
.\".It Fl Ns Ar n
.\"(Deprecated; replaced by
.\".Fl f ) .
diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c
index 2668c964d4e13..e92e597b3da8f 100644
--- a/usr.bin/uniq/uniq.c
+++ b/usr.bin/uniq/uniq.c
@@ -51,6 +51,7 @@ static const char rcsid[] =
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <getopt.h>
#include <limits.h>
#include <locale.h>
#include <nl_types.h>
@@ -66,6 +67,17 @@ static const char rcsid[] =
static int cflag, dflag, uflag, iflag;
static int numchars, numfields, repeats;
+static const struct option long_opts[] =
+{
+ {"count", no_argument, NULL, 'c'},
+ {"repeated", no_argument, NULL, 'd'},
+ {"skip-fields", required_argument, NULL, 'f'},
+ {"ignore-case", no_argument, NULL, 'i'},
+ {"skip-chars", required_argument, NULL, 's'},
+ {"unique", no_argument, NULL, 'u'},
+ {NULL, no_argument, NULL, 0}
+};
+
static FILE *file(const char *, const char *);
static wchar_t *convert(const char *);
static int inlcmp(const char *, const char *);
@@ -99,7 +111,8 @@ main (int argc, char *argv[])
(void) setlocale(LC_ALL, "");
obsolete(argv);
- while ((ch = getopt(argc, argv, "cdif:s:u")) != -1)
+ while ((ch = getopt_long(argc, argv, "+cdif:s:u", long_opts,
+ NULL)) != -1)
switch (ch) {
case 'c':
cflag = 1;