package main import ( "fmt" "os" "bufio" "strings" "flag" ) type Opts struct { IgnoreCase bool Count bool } func ParseOpts() 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 StringEqual(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 := ParseOpts() for scan.Scan() { line := scan.Text() if !StringEqual(line, seen_line, opts.IgnoreCase) { if opts.Count { fmt.Print(seen_count, " ") } fmt.Println(line) seen_line = line seen_count = 0 } else { seen_count++ } } }