Skip to content

Instantly share code, notes, and snippets.

@cowens
Created November 6, 2017 13:45
Show Gist options
  • Save cowens/1c56c2f1d644a8b9b9a46be09becffbd to your computer and use it in GitHub Desktop.
Save cowens/1c56c2f1d644a8b9b9a46be09becffbd to your computer and use it in GitHub Desktop.
package main
import (
b "bufio"
f "fmt"
l "log"
"os"
r "regexp"
"strconv"
)
func intify(s string) int {
n, err := strconv.Atoi(s)
if err != nil {
l.Fatal(err)
}
return n
}
func main() {
scanner := b.NewScanner(os.Stdin)
regex := r.MustCompile("(.*)\t(.*)/(.*)/(.*)")
for scanner.Scan() {
line := scanner.Text()
matches := regex.FindStringSubmatch(line)
if len(matches) != 0 {
year := intify(matches[4])
month := intify(matches[3])
day := intify(matches[2])
f.Printf("%s\t%04d-%02d-%02d\n", matches[1], year, month, day)
} else {
f.Println("no match")
}
}
if err := scanner.Err(); err != nil {
l.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment