github.com/gogo/protobuf@v1.3.2/gogoreplace/main.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "fmt" 6 "io/ioutil" 7 "os" 8 ) 9 10 func main() { 11 args := os.Args 12 if len(args) != 4 { 13 fmt.Println("gogoreplace wants three arguments") 14 fmt.Println(" gogoreplace oldsubstring newsubstring filename") 15 os.Exit(1) 16 } 17 data, err := ioutil.ReadFile(args[3]) 18 if err != nil { 19 panic(err) 20 } 21 data = bytes.Replace(data, []byte(args[1]), []byte(args[2]), -1) 22 if err := ioutil.WriteFile(args[3], data, 0666); err != nil { 23 panic(err) 24 } 25 }