I use uniq for some log file analysis and it contained "duplicate"
lines which only differ in lower/upper case (user input). Hence I
added an -i flag which also exists on FreeBSD at least.
Maybe it's useful to add to OpenBSD?

Index: uniq.1
===================================================================
RCS file: /home/ca/OpenBSD/cvs/src/usr.bin/uniq/uniq.1,v
retrieving revision 1.19
diff -u -r1.19 uniq.1
--- uniq.1      24 Oct 2016 13:46:58 -0000      1.19
+++ uniq.1      15 Dec 2017 11:35:53 -0000
@@ -43,6 +43,7 @@
 .Nm uniq
 .Op Fl c
 .Op Fl d | u
+.Op Fl i
 .Op Fl f Ar fields
 .Op Fl s Ar chars
 .Oo
@@ -73,6 +74,8 @@
 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
Index: uniq.c
===================================================================
RCS file: /home/ca/OpenBSD/cvs/src/usr.bin/uniq/uniq.c,v
retrieving revision 1.24
diff -u -r1.24 uniq.c
--- uniq.c      19 Dec 2015 10:21:01 -0000      1.24
+++ uniq.c      15 Dec 2017 11:30:46 -0000
@@ -47,7 +47,7 @@
 
 #define        MAXLINELEN      (8 * 1024)
 
-int cflag, dflag, uflag;
+int cflag, dflag, uflag, iflag;
 int numchars, numfields, repeats;
 
 FILE   *file(char *, char *);
@@ -70,7 +70,7 @@
                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 @@
                                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 @@
                }
 
                /* 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;

Reply via email to