// ReplaceLine replaces any line in the file at the given path that begins with linePrefix with the given replacement
// string.
ReplaceLine replaces any line in the file at the given path that begins with linePrefix with the given replacement
string.
// ReplaceLine replaces any line in the file at the given path that begins with linePrefix with the given replacement // string .
func ReplaceLine(path, linePrefix, replacement string) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return fmt.Errorf("couldn't replace file's line: %v", err)
	}
	lines := strings.Split(string(data), "\n")
	for i, l := range lines {
		if strings.HasPrefix(l, linePrefix) {
			lines[i] = replacement
		}
	}
	output := strings.Join(lines, "\n")
	err = ioutil.WriteFile(path, []byte(output), 0644)
	if err != nil {
		return fmt.Errorf("failed to write replacement file: %v", err)
	}
	return nil
}
func ReplaceLine ( path , linePrefix , replacement string ) error { data , err := ioutil . ReadFile ( path ) if err != nil { return fmt . Errorf ( " " , err ) } lines := strings . Split ( string ( data ) , " \n " ) for i , l := range lines { if strings . HasPrefix ( l , linePrefix ) { lines [ i ] = replacement } } output := strings . Join ( lines , " \n " ) err = ioutil . WriteFile ( path , [ ] byte ( output ) , 0644 ) if err != nil { return fmt . Errorf ( " " , err ) } return nil }
ReplaceLine replaces any line in the file at the given path that begins with linePrefix with the given replacement
string.
ReplaceLine replaces any line in the file at the given path that begins with linePrefix with the given replacement string .