/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* uniq
*
* Written by David Korn
*/
static const char usage[] =
"[-n?\n@(#)$Id: uniq (AT&T Research) 2009-11-28 $\n]"
"[+NAME?uniq - Report or filter out repeated lines in a file]"
"[+DESCRIPTION?\buniq\b reads the input, compares adjacent lines, and "
"writes one copy of each input line on the output. The second "
"and succeeding copies of the repeated adjacent lines are not "
"written.]"
"[+?If the output file, \aoutfile\a, is not specified, \buniq\b writes "
"to standard output. If no \ainfile\a is given, or if the \ainfile\a "
"is \b-\b, \buniq\b reads from standard input with the start of "
"the file defined as the current offset.]"
"[c:count?Output the number of times each line occurred along with "
"the line.]"
"[d:repeated|duplicates?Output the first of each duplicate line.]"
"[D:all-repeated?Output all duplicate lines as a group with an empty "
"line delimiter specified by \adelimit\a:]:?[delimit:=none]"
"{"
"[n:none?Do not delimit duplicate groups.]"
"[p:prepend?Prepend an empty line before each group.]"
"[s:separate?Separate each group with an empty line.]"
"}"
"[f:skip-fields]#[fields?\afields\a is the number of fields to skip over "
"before checking for uniqueness. A field is the minimal string matching "
"the BRE \b[[:blank:]]]]*[^[:blank:]]]]*\b. -\anumber\a is equivalent to "
"\b--skip-fields\b=\anumber\a.]"
"[i:ignore-case?Ignore case in comparisons.]"
"[s:skip-chars]#[chars?\achars\a is the number of characters to skip over "
"before checking for uniqueness. If specified along with \b-f\b, "
"the first \achars\a after the first \afields\a are ignored. If "
"the \achars\a specifies more characters than are on the line, "
"an empty string will be used for comparison. +\anumber\a is "
"equivalent to \b--skip-chars\b=\anumber\a.]"
"[u:unique?Output unique lines.]"
"[w:check-chars]#[chars?\achars\a is the number of characters to compare "
"after skipping any specified fields and characters.]"
"\n"
"\n[infile [outfile]]\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?The input file was successfully processed.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bsort\b(1), \bgrep\b(1)]"
;
#include <cmd.h>
static int uniq(Sfio_t *fdin, Sfio_t *fdout, int fields, int chars, int width, int mode, int* all, Compare_f compare)
{
while(1)
{
{
bufp[n++] = '\n';
}
else
n = 0;
if (n)
{
if (f = fields)
{
cp++;
cp++;
}
if (chars)
{
if (mb)
for (f = chars; f; f--)
else
}
{
reclen = 1;
}
{
if (mb)
{
reclen = 0;
{
reclen++;
}
}
else
}
}
else
reclen = -2;
{
count++;
if (!all)
continue;
}
else
{
next = 0;
if(outsize>0)
{
{
}
else
{
if(cwidth)
{
if(count<9)
{
f = 0;
while(f < CWIDTH-1)
outp[f++] = ' ';
outp[f] = ' ';
}
{
count++;
f = CWIDTH;
outp[f--] = ' ';
do
{
} while (count /= 10);
while (f >= 0)
outp[f--] = ' ';
}
else
{
{
return(1);
}
else
}
}
return(1);
}
}
}
if(n==0)
break;
{
return(1);
if(*all >= 0)
*all = 1;
sep = 0;
}
else
/* save current record */
return(1);
{
/* no room in outp, clear lock and use side buffer */
return(1);
}
else
if(sep)
}
return(0);
}
int
{
register int n, mode=0;
register char *cp;
int* all = 0;
int sep;
for (;;)
{
{
case 'c':
continue;
case 'd':
continue;
case 'D':
{
case 'p':
sep = 1;
break;
case 's':
sep = 0;
break;
default:
sep = -1;
break;
}
continue;
case 'i':
continue;
case 'u':
continue;
case 'f':
else
continue;
case 's':
continue;
case 'w':
continue;
case ':':
break;
case '?':
break;
}
break;
}
if(error_info.errors)
{
}
else
{
argv++;
}
else
if(*argv)
{
}
return(error_info.errors);
}