Created
November 6, 2017 13:45
-
-
Save cowens/1c56c2f1d644a8b9b9a46be09becffbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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