Created
May 28, 2014 06:41
-
-
Save hymkor/f3c9b631ef6598193827 to your computer and use it in GitHub Desktop.
goによるテキストファイル操作テンプレ(自分用) ref: http://qiita.com/zetamatta/items/a3f421297970468c3dd9
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 "bufio" | |
import "io" | |
import "os" | |
import "regexp" | |
import "fmt" | |
var ansiStrip = regexp.MustCompile("\x1B[^a-zA-Z]*[A-Za-z]") | |
func cat1(r io.Reader) { | |
scanner := bufio.NewScanner(r) | |
for scanner.Scan() { | |
fmt.Println(ansiStrip.ReplaceAllString(scanner.Text(), "")) | |
} | |
} | |
func main() { | |
for _, arg1 := range os.Args[1:] { | |
r, err := os.Open(arg1) | |
if err != nil { | |
fmt.Fprintln(os.Stderr, err.Error()) | |
return | |
} | |
cat1(r) | |
r.Close() | |
} | |
if len(os.Args) <= 1 { | |
cat1(os.Stdin) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment