Skip to content

Instantly share code, notes, and snippets.

@unstppbl
Created February 25, 2019 10:39
Show Gist options
  • Save unstppbl/94fbe8d0e98577bcc7203f1b909836cf to your computer and use it in GitHub Desktop.
Save unstppbl/94fbe8d0e98577bcc7203f1b909836cf to your computer and use it in GitHub Desktop.
Basic text files formatter
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