parent
be54bf3e7d
commit
55fc99e01f
@ -0,0 +1,2 @@ |
|||||||
|
uniq |
||||||
|
uniq.exe |
||||||
@ -0,0 +1,4 @@ |
|||||||
|
|
||||||
|
|
||||||
|
build: |
||||||
|
go build .
|
||||||
@ -0,0 +1,3 @@ |
|||||||
|
module lcthw.dev/go/go-coreutils/uniq |
||||||
|
|
||||||
|
go 1.25.3 |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"os" |
||||||
|
"bufio" |
||||||
|
"strings" |
||||||
|
"flag" |
||||||
|
) |
||||||
|
type Opts struct { |
||||||
|
IgnoreCase bool |
||||||
|
Count bool |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
func parse_opts() Opts { |
||||||
|
var opts Opts |
||||||
|
|
||||||
|
flag.BoolVar(&opts.IgnoreCase, "i", false, "ignore case") |
||||||
|
flag.BoolVar(&opts.Count, "c", false, "count occurence") |
||||||
|
flag.Parse() |
||||||
|
|
||||||
|
return opts |
||||||
|
} |
||||||
|
|
||||||
|
func string_equal(a string, b string, ignore_case bool) bool { |
||||||
|
if ignore_case { |
||||||
|
a = strings.ToLower(a) |
||||||
|
b = strings.ToLower(b) |
||||||
|
} |
||||||
|
|
||||||
|
return strings.Compare(a, b) == 0 |
||||||
|
} |
||||||
|
|
||||||
|
func main() { |
||||||
|
scan := bufio.NewScanner(os.Stdin) |
||||||
|
seen_line := "" |
||||||
|
seen_count := 0 |
||||||
|
opts := parse_opts() |
||||||
|
|
||||||
|
for scan.Scan() { |
||||||
|
line := scan.Text() |
||||||
|
|
||||||
|
if !string_equal(line, seen_line, opts.IgnoreCase) { |
||||||
|
if opts.Count { |
||||||
|
fmt.Print(seen_count, " ") |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Println(line) |
||||||
|
|
||||||
|
seen_line = line |
||||||
|
seen_count = 0 |
||||||
|
} else { |
||||||
|
seen_count++ |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
head |
||||||
|
numfmt |
||||||
|
od |
||||||
|
sha512sum |
||||||
|
sort |
||||||
|
starter |
||||||
|
starter |
||||||
|
starter |
||||||
|
LICENSE |
||||||
|
license |
||||||
|
LICENSE |
||||||
|
outline.txt |
||||||
|
README.md |
||||||
|
stat |
||||||
|
tail |
||||||
|
tail |
||||||
|
tail |
||||||
|
tail |
||||||
|
tr |
||||||
|
uniq |
||||||
|
uniq |
||||||
|
uniq |
||||||
|
uniq |
||||||
|
cat |
||||||
|
cat |
||||||
|
cat |
||||||
|
cat |
||||||
|
date |
||||||
|
du |
||||||
|
wc |
||||||
|
.gitignore |
||||||
Loading…
Reference in new issue