Skip to content

Instantly share code, notes, and snippets.

@oozzal
Last active August 29, 2015 14:02
Show Gist options
  • Save oozzal/99739953695952ecdc5f to your computer and use it in GitHub Desktop.
Save oozzal/99739953695952ecdc5f to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"os"
"strings"
)
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func main() {
var mix_file, mix_err = ioutil.ReadFile("mixture")
var fil_file, fil_err = ioutil.ReadFile("filter")
var out_file, out_err = os.OpenFile("final_output", os.O_APPEND|os.O_WRONLY, 0600)
if mix_err != nil {
panic(mix_err)
}
if fil_err != nil {
panic(fil_err)
}
if out_err != nil {
panic(out_err)
}
defer out_file.Close()
var mix_list = strings.Split(string(mix_file), "\n")
var fil_list = strings.Split(string(fil_file), "\n")
// An empty string at the last after the split
var search_len = len(mix_list) - 1
for i := 0; i < search_len; i++ {
if stringInSlice(mix_list[i], fil_list) {
if _, out_err = out_file.WriteString(mix_list[i] + "\n"); out_err != nil {
panic(out_err)
}
}
}
out_file.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment