-- Select the files you want to change content replace_file = { "e:/test/toto.conf", "e:/test/titi.conf", } -- Select the string you want to replace in bracket by the string after the equal replace_string = { ["toto"] = "titi", ["titi"] = "tata", } -- Put "\n" for unix, "\r\n" for windows line_feed = "\n" -- Program starts here -- Loop for files given into the replace_file table -- Then loop for lines into each file -- Finally replace each line when its necessary for _,filename in pairs(replace_file) do local fp,err = io.open(filename) if fp then local filechanged = 0 local output = "" for inline in fp:lines() do local outline = inline for i,j in pairs(replace_string) do outline = string.gsub(outline,i,j) end if inline ~= outline then filechanged = filechanged + 1 end output = output .. outline .. line_feed end fp:close() if filechanged > 0 then local fp, err = io.open(filename,"wb") if fp then fp:write(output) fp:close() print("CHANGED : "..filename.." ("..filechanged.." lines)") else print("FAILED : "..err.." (during file writing)") end else print("UNCHANGED : "..filename) end else print("FAILED : "..err.." (during file reading)") end end