Skip to content

Instantly share code, notes, and snippets.

@arc279
Last active January 27, 2017 06:36
Show Gist options
  • Save arc279/9d42d6129039c0d3815440528737296f to your computer and use it in GitHub Desktop.
Save arc279/9d42d6129039c0d3815440528737296f to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"encoding/csv"
"fmt"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/transform"
"io"
"os"
"strings"
)
func main() {
fp := os.Stdin
reader := csv.NewReader(transform.NewReader(bufio.NewReader(fp), japanese.ShiftJIS.NewDecoder()))
reader.Comma = '\t'
reader.LazyQuotes = true
for {
record, err := reader.Read()
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
fmt.Println(strings.Join(record[3:6], ":"))
}
}
# -*- coding: utf-8 -*-
import csv
import sys
import io
fp = open(sys.stdin.fileno(), 'r', encoding='sjis')
tsv = csv.reader(fp, delimiter = '\t')
for row in tsv:
print(":".join(row[3:5]))
$ uname -a
Darwin XXX 15.6.0 Darwin Kernel Version 15.6.0: Wed Nov 2 20:30:56 PDT 2016; root:xnu-3248.60.11.1.2~2/RELEASE_X86_64 x86_64 i386 MacBookPro11,1 Darwin
$ wc -l a.tsv
1000000 a.tsv
$ file --mime a.tsv
a.tsv: text/plain; charset=unknown-8bit
$ go version
go version go1.7 darwin/amd64
# go build
$ time cat a.tsv | ./a > /dev/null
real 0m4.691s
user 0m4.349s
sys 0m0.470s
$ python -V
Python 3.5.2 :: Anaconda custom (x86_64)
$ time cat a.tsv | python a.py > /dev/null
real 0m4.682s
user 0m4.584s
sys 0m0.185s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment