package main

import (
	"log"
	"os"
)

func main() {
	if len(os.Args) != 3 {
		log.Fatalf("Usage: %s data_file pattterns_file", os.Args[0])
	}

	dataFile, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatalf("Error occurred while opening data_file: %v", err)
	}
	defer dataFile.Close()

	patternsFile, err := os.Open(os.Args[2])
	if err != nil {
		log.Fatalf("Error occurred while opening patterns_file: %v", err)
	}
	defer patternsFile.Close()

	status := OrderedIntersect(dataFile, patternsFile, os.Stdout)
	os.Exit(status)
}
package main

import (
	"os"
	"flag"
	"log"
)

func main() {
	var pArg = flag.String("p", "patterns", "patterns file")
	flag.Parse()

	patternsFile, err := os.Open(*pArg)
	if err != nil {
		log.Fatalf("Error occurred while opening patterns_file: %v", err)
	}
	defer patternsFile.Close()

	var dataFile = os.Stdin
	if len(os.Args) == 4 {
		dataFile, err = os.Open(flag.Arg(0))
		if err != nil {
			log.Fatalf("Error occurred while opening data_file: %v", err)
		}
	}

	status := OrderedIntersect(dataFile, patternsFile, os.Stdout)
	os.Exit(status)
}
Support reading data from stdin
Support reading data from stdin
