diff options
author | Nick White <git@njw.name> | 2020-02-27 17:45:16 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2020-02-27 17:45:16 +0000 |
commit | 3880414bbf2d6f2cd05e208abf919ae5ceabeddc (patch) | |
tree | dee30a151048de65a3e42cfdae7739c4502e148f /cmd/boxtotxt | |
parent | cda45588cfb796fdd2af27b1851685270df2c02b (diff) |
Reorganise all commands to be behind cmd/
Diffstat (limited to 'cmd/boxtotxt')
-rw-r--r-- | cmd/boxtotxt/main.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/cmd/boxtotxt/main.go b/cmd/boxtotxt/main.go new file mode 100644 index 0000000..058eb05 --- /dev/null +++ b/cmd/boxtotxt/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "bufio" + "flag" + "fmt" + "log" + "os" + "strings" +) + +func main() { + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage: boxtotxt in.box\n") + flag.PrintDefaults() + } + flag.Parse() + if flag.NArg() != 1 { + flag.Usage() + os.Exit(1) + } + + f, err := os.Open(flag.Arg(0)) + defer f.Close() + if err != nil { + log.Fatalf("Could not open file %s: %v\n", flag.Arg(0), err) + } + + scanner := bufio.NewScanner(f) + + for scanner.Scan() { + t := scanner.Text() + s := strings.Split(t, "") + if len(s) < 1 { + continue + } + if s[0] == "\t" { + continue + } + fmt.Printf("%s", s[0]) + } + + fmt.Printf("\n") +} |