Skip to content

Instantly share code, notes, and snippets.

@jduck
Created February 23, 2015 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jduck/ebca1d6a56618b66e986 to your computer and use it in GitHub Desktop.
Save jduck/ebca1d6a56618b66e986 to your computer and use it in GitHub Desktop.
--- src/uniq.c.orig 2013-01-30 18:46:24.000000000 -0600
+++ src/uniq.c 2015-02-23 02:30:06.000000000 -0600
@@ -66,6 +66,7 @@
enum countmode
{
count_occurrences, /* -c Print count before output lines. */
+ count_syslog, /* -l Print "last line repeated XX times" */
count_none /* Default. Do not print counts. */
};
@@ -268,6 +269,9 @@
printf ("%7" PRIuMAX " ", linecount + 1);
fwrite (line->buffer, sizeof (char), line->length, stdout);
+
+ if (countmode == count_syslog && linecount > 0)
+ printf ("*** last line repeated %d times ***\n", linecount);
}
/* Process input file INFILE with output to OUTFILE.
@@ -443,7 +447,7 @@
if (optc == -1
|| (posixly_correct && nfiles != 0)
|| ((optc = getopt_long (argc, argv,
- "-0123456789Dcdf:is:uw:z", longopts, NULL))
+ "-0123456789Dcdlf:is:uw:z", longopts, NULL))
== -1))
{
if (argc <= optind)
@@ -525,6 +529,10 @@
ignore_case = true;
break;
+ case 'l':
+ countmode = count_syslog;
+ break;
+
case 's':
skip_chars = size_opt (optarg,
N_("invalid number of bytes to skip"));
@@ -552,7 +560,7 @@
}
}
- if (countmode == count_occurrences && output_later_repeated)
+ if (countmode != count_none && output_later_repeated)
{
error (0, 0,
_("printing all duplicated lines and repeat counts is meaningless"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment