diff options
| author | Charles Forsyth <charles.forsyth@gmail.com> | 2024-04-22 06:59:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-22 06:59:12 +0100 |
| commit | 3461be9f61d07b89d9e41f771f7bcdff2e0ba0b6 (patch) | |
| tree | cb954a79dc249e850fe0636458e1b47e873d23ca | |
| parent | 54b1df79e786e6e814d581a73354fc955a33793e (diff) | |
| parent | 68b5462cb24decbfc1baac0c323201dec655d850 (diff) | |
Merge pull request #15 from pete/add-uniq-c
Add uniq -c
| -rw-r--r-- | appl/cmd/uniq.b | 15 | ||||
| -rw-r--r-- | man/1/uniq | 5 |
2 files changed, 16 insertions, 4 deletions
diff --git a/appl/cmd/uniq.b b/appl/cmd/uniq.b index 4442c22f..9846e69f 100644 --- a/appl/cmd/uniq.b +++ b/appl/cmd/uniq.b @@ -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) @@ -31,6 +31,7 @@ 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 { @@ -38,6 +39,8 @@ init(nil : ref Draw->Context, args : list of string) uflag = 1; 'd' => dflag = 1; + 'c' => + cflag = 1; * => usage(); } @@ -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(); } @@ -4,7 +4,7 @@ uniq \- report repeated lines in a file .SH SYNOPSIS .B uniq [ -.B -ud +.B -udc ] [ .I file @@ -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 |
