Finding Duplicate Lines



👍 cat dup1.in 
good morning
good afternoon
bye
bye
hi
hello
hi
hello
hello

👍 go run dup1.go < dup1.in 
3	hello
2	bye
2	hi

👍 cat dup1.go 
package main

import (
  "bufio"
  "fmt"
  "os"
)

func main() {
  counts := make(map[string]int)
  input := bufio.NewScanner(os.Stdin)
  for input.Scan() {
    counts[input.Text()]++
  }
  for line, n := range counts {
    if n > 1 {
      fmt.Printf("%d\t%s\n", n, line)
    }
  }
}

    

ch 1.3 Finding Duplicate Lines p27/8 of