Skipping error checking for brevity (ok, laziness maybe a bit too ;-) ..
Using the same 'logic' as your awk pgm, you could do something like the following in Go :
(Please note that I am also a go beginner, so any comments or suggestions from the 'pros' are welcome, thx)
you can run it with: go run mergeCSV.go file1.csv file2.csv > merged.csv
(file1,csv being the large ref file used to create the index)
I hope this can be helpful
-------
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func buildIndex(filename1 string) (ret map[string]string) {
var index = make(map[string]string)
file, _ := os.Open(filename1)
scanner := bufio.NewScanner(file)
defer file.Close()
for scanner.Scan() {
ln := scanner.Text()
fields := strings.Split(ln, "\t")
index[fields[0]] = fields[1]
}
return index
}
func doLookup(filename2 string, index map[string]string) {
file, _ := os.Open(filename2)
scanner := bufio.NewScanner(file)
defer file.Close()
for scanner.Scan() {
ln := scanner.Text()
fields := strings.Split(ln, "\t")
key := fields[3]
if foundValue, ok := index[key]; ok {
fmt.Printf("%s\t%s\n", ln, foundValue)
}
}
}
func main() {
index := buildIndex(os.Args[1])
doLookup(os.Args[2], index)