Skip to content

Instantly share code, notes, and snippets.

@dallarosa
Created October 2, 2014 01:14
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dallarosa/b58b0e3425761e0a7cf6 to your computer and use it in GitHub Desktop.
Save dallarosa/b58b0e3425761e0a7cf6 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)
}
}
@AllanCapistrano
Copy link

Hey, ioutil is deprecated now, but we can use the os package instead.

@dallarosa
Copy link
Author

@AllanCapistrano Thank you for this! I'll fix it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment