Skip to content

Instantly share code, notes, and snippets.

@virtualsafety
Forked from dallarosa/replace.go
Created September 4, 2020 06:53
Show Gist options
  • Save virtualsafety/7c55d7872017e559fb45ab124a64470f to your computer and use it in GitHub Desktop.
Save virtualsafety/7c55d7872017e559fb45ab124a64470f to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"log"
"strings"
)
func main() {
input, err := ioutil.ReadFile("myfile")
if err != nil {
log.Fatalln(err)
}
lines := strings.Split(string(input), "\n")
for i, line := range lines {
if strings.Contains(line, "]") {
lines[i] = "LOL"
}
}
output := strings.Join(lines, "\n")
err = ioutil.WriteFile("myfile", []byte(output), 0644)
if err != nil {
log.Fatalln(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment