I'm trying to change contents of a file based on a pattern and save the file in the same directory. Below is my code,
designFile <- "/proj/desk/design.scs"
designFile <- readLines(designFile)
pattern <- "esd_event"
rownos <- grep(pattern, designfile)
rownotoreplace <- rownos[length(rownos)]
print(designfile[rownotoreplace])
designFile[rownotoreplace] <- paste("+ esd_event=", input$esd_event, sep="")
filename = designfile
fConn <- file(filename,open="w")
for(i in 1:length(designFile)){
writeLines(designFile[i], con = fConn, sep = "")
}
close(fConn)
The file in which the string change looks like,
+ cor_zgdiode = sigma
+ corner_sigma = 3
+ corner_sigma_sg = corner_sigma
+ corner_sigma_eg = corner_sigma
+ corner_sigma_sram = corner_sigma
+ corner_sigma_ldmos = corner_sigma
+ corner_sigma_wire = corner_sigma
+ cor_noin = 0
+ cor_noip = 0
+ cor_tnoin = 0
+ cor_tnoip = 0
+ fnoi_cor_sgn_sw = cor_noin
+ fnoi_cor_egn_sw = cor_noin
+ fnoi_mc_sgn_sw = 1
+ fnoi_mc_egn_sw = 1
+ fnoi_cor_sgp_sw = cor_noip
+ fnoi_cor_egp_sw = cor_noip
+ fnoi_mc_sgp_sw = 1
+ fnoi_mc_egp_sw = 1
* ESD Global switches ********
+ esd_event=0
+ esd_exit=1
+ esd_extr=0
The contents of the file is dynamic and the number of lines might vary based on user input. I'm able to replace the string, "esd_event" with my code that I attached, but I'm not able to save the file in the same directory after replacing the string.
I would like to know how to save