function replaceFile(path, fn)
local file = io.open(path, "r+")
if file then
local data = file:read("*a")
data = fn(data)
file:close()
local file = io.open(path, "w+")
if file then
file:write(data):close()
return true
end
end
end
-- example
replaceFile("./negr.txt", function (data)
-- omfg code
return data:gsub("kizn", "itzkisn"):gsub("yondime", "чурка")
end)