I have a file named aab.inc and i have a line $VP_Name="Some Messages" I wrote a code in golang so that it reads the file aab.inc and Removes any line that has a word VP_Name and in my code i also included that That line(which contains the word VP_Name) is replaced with $VP_Name="Alternate Message" but my problem is it never deletes the line if i give the word as $VP_Name and it replaces the line as ="Alternate Message" in the place if I give the replacing word as $VP_Name="Alternate Message" . But it deletes the line if give the word as VP_Name alone(Without $) and replaces the line as VP_Name="Alternate Message" if the replacing text is given without the $ symbol.
My code is as follows
package main
import "fmt"
import "regexp"
import "os"
import "io/ioutil"
func main() {
ConfigFile1, err := os.Open("aab.inc")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer ConfigFile1.Close()
ConfigFiledata1, _ := ioutil.ReadAll(ConfigFile1)
//Try with $VP_Name
re := regexp.MustCompile("(?m)[
]+^.*VP_Name.*$")
// Actual Word is $VP_Name="Alternate Message"
res := re.ReplaceAllString(string(ConfigFiledata1), "
VP_Name=\"Alternate Message\"")
fmt.Println(res)
out := []byte(res)
if err := ioutil.WriteFile("aab_final.inc",out, 0666); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
The new replaced line should come in the next line should not append with any other lines but even i use before the replacing text the result is as below
Output
$VP_Roll="";VP_Name="Alternate Message";
$VP_Failure="Yes";
What is the Problem in including the $ in the code and why the text is not replaced in a new line even was specified.
Thanks in Advance