Created
February 25, 2019 10:39
-
-
Save unstppbl/94fbe8d0e98577bcc7203f1b909836cf to your computer and use it in GitHub Desktop.
Basic text files formatter
This file contains hidden or 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 ( | |
"bufio" | |
"log" | |
"os" | |
"strings" | |
) | |
func checkErr(err error) { | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
const countryCode = "sg" | |
func main() { | |
from, err := os.Open(countryCode + ".csv") | |
checkErr(err) | |
defer from.Close() | |
to, err := os.Create(countryCode + ".txt") | |
checkErr(err) | |
defer to.Close() | |
scanner := bufio.NewScanner(from) | |
for scanner.Scan() { | |
line := scanner.Text() | |
data := strings.Split(line, " ") | |
to.WriteString(data[0] + "\n") | |
} | |
checkErr(scanner.Err()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment