Skip to content

Commit

Permalink
Merge pull request #15 from pete/add-uniq-c
Browse files Browse the repository at this point in the history
Add uniq -c
  • Loading branch information
forsyth committed Apr 22, 2024
2 parents 54b1df7 + 68b5462 commit 3461be9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 12 additions & 3 deletions appl/cmd/uniq.b
Expand Up @@ -13,7 +13,7 @@ Uniq: module

usage()
{
fail("usage", sys->sprint("usage: uniq [-ud] [file]"));
fail("usage", sys->sprint("usage: uniq [-udc] [file]"));
}

init(nil : ref Draw->Context, args : list of string)
Expand All @@ -31,13 +31,16 @@ init(nil : ref Draw->Context, args : list of string)

uflag := 0;
dflag := 0;
cflag := 0;
arg->init(args);
while ((opt := arg->opt()) != 0) {
case opt {
'u' =>
uflag = 1;
'd' =>
dflag = 1;
'c' =>
cflag = 1;
* =>
usage();
}
Expand All @@ -61,14 +64,20 @@ init(nil : ref Draw->Context, args : list of string)
if (s == prev)
n++;
else {
if ((uflag && n == 1) || (dflag && n > 1))
if ((uflag && n == 1) || (dflag && n > 1)) {
if(cflag)
prev = string n + "\t" + prev;
stdout.puts(prev);
}
n = 1;
prev = s;
}
}
if ((uflag && n == 1) || (dflag && n > 1))
if ((uflag && n == 1) || (dflag && n > 1)) {
if(cflag)
prev = string n + "\t" + prev;
stdout.puts(prev);
}
stdout.close();
}

Expand Down
5 changes: 4 additions & 1 deletion man/1/uniq
Expand Up @@ -4,7 +4,7 @@ uniq \- report repeated lines in a file
.SH SYNOPSIS
.B uniq
[
.B -ud
.B -udc
]
[
.I file
Expand All @@ -24,6 +24,9 @@ in order to be found.
.B -u
Print unique lines.
.TP
.B -c
Prefix a repetition count and a tab to each output line.
.TP
.B -d
Print (one copy of) duplicated lines.
.SH SOURCE
Expand Down

0 comments on commit 3461be9

Please sign in to comment.