summaryrefslogtreecommitdiff
path: root/usr.bin/uniq
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2017-12-21 10:06:00 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2017-12-21 10:06:00 +0000
commit3686b75faa3c8c1f957816b2c18863bea4ccad88 (patch)
treec6a4b25a7d31b0978491297e2b6ed769f52f4a31 /usr.bin/uniq
parentb3087c6fa0941229359be2e0d3e7dda917a9f5b9 (diff)
Add an -i option for case insensitive comparison of lines.
From Claus Assmann with minor tweaks by me. ok millert
Diffstat (limited to 'usr.bin/uniq')
-rw-r--r--usr.bin/uniq/uniq.114
-rw-r--r--usr.bin/uniq/uniq.c13
2 files changed, 17 insertions, 10 deletions
diff --git a/usr.bin/uniq/uniq.1 b/usr.bin/uniq/uniq.1
index 1c3f10cad8d..a5e1f5ba8c9 100644
--- a/usr.bin/uniq/uniq.1
+++ b/usr.bin/uniq/uniq.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: uniq.1,v 1.19 2016/10/24 13:46:58 schwarze Exp $
+.\" $OpenBSD: uniq.1,v 1.20 2017/12/21 10:05:59 tb Exp $
.\" $NetBSD: uniq.1,v 1.5 1994/12/06 07:51:15 jtc Exp $
.\"
.\" Copyright (c) 1991, 1993
@@ -33,7 +33,7 @@
.\"
.\" @(#)uniq.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd $Mdocdate: October 24 2016 $
+.Dd $Mdocdate: December 21 2017 $
.Dt UNIQ 1
.Os
.Sh NAME
@@ -41,7 +41,7 @@
.Nd report or filter out repeated lines in a file
.Sh SYNOPSIS
.Nm uniq
-.Op Fl c
+.Op Fl ci
.Op Fl d | u
.Op Fl f Ar fields
.Op Fl s Ar chars
@@ -73,6 +73,8 @@ in each input line when doing comparisons.
A field is a string of non-blank characters separated from adjacent fields
by blanks, with blanks considered part of the following field.
Field numbers are one based, i.e., the first field is field one.
+.It Fl i
+Case insensitive comparison of lines.
.It Fl s Ar chars
Ignore the first
.Ar chars
@@ -138,13 +140,15 @@ utility is compliant with the
.St -p1003.1-2008
specification.
.Pp
-The use of
+The
+.Fl i
+option and the use of
.Fl c
in conjunction with
.Fl d
or
.Fl u
-is an extension to that specification.
+are extensions to that specification.
.Pp
The historic
.Cm + Ns Ar number
diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c
index 7e4d7b86a11..e2cc67332ca 100644
--- a/usr.bin/uniq/uniq.c
+++ b/usr.bin/uniq/uniq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uniq.c,v 1.24 2015/12/19 10:21:01 schwarze Exp $ */
+/* $OpenBSD: uniq.c,v 1.25 2017/12/21 10:05:59 tb Exp $ */
/* $NetBSD: uniq.c,v 1.7 1995/08/31 22:03:48 jtc Exp $ */
/*
@@ -47,7 +47,7 @@
#define MAXLINELEN (8 * 1024)
-int cflag, dflag, uflag;
+int cflag, dflag, iflag, uflag;
int numchars, numfields, repeats;
FILE *file(char *, char *);
@@ -70,7 +70,7 @@ main(int argc, char *argv[])
err(1, "pledge");
obsolete(argv);
- while ((ch = getopt(argc, argv, "cdf:s:u")) != -1) {
+ while ((ch = getopt(argc, argv, "cdf:is:u")) != -1) {
const char *errstr;
switch (ch) {
@@ -87,6 +87,9 @@ main(int argc, char *argv[])
errx(1, "field skip value is %s: %s",
errstr, optarg);
break;
+ case 'i':
+ iflag = 1;
+ break;
case 's':
numchars = (int)strtonum(optarg, 0, INT_MAX,
&errstr);
@@ -149,7 +152,7 @@ main(int argc, char *argv[])
}
/* If different, print; set previous to new value. */
- if (strcmp(t1, t2)) {
+ if ((!iflag && strcmp(t1, t2)) || strcasecmp(t1, t2)) {
show(ofp, prevline);
t1 = prevline;
prevline = thisline;
@@ -257,7 +260,7 @@ usage(void)
extern char *__progname;
(void)fprintf(stderr,
- "usage: %s [-c] [-d | -u] [-f fields] [-s chars] [input_file [output_file]]\n",
+ "usage: %s [-ci] [-d | -u] [-f fields] [-s chars] [input_file [output_file]]\n",
__progname);
exit(1);
}