RosettaCodeData/Task/Globally-replace-text-in-several-files/Lua/globally-replace-text-in-several-files.lua
2023-07-01 13:44:08 -04:00

12 lines
278 B
Lua

filenames = { "f1.txt", "f2.txt" }
for _, fn in pairs( filenames ) do
fp = io.open( fn, "r" )
str = fp:read( "*all" )
str = string.gsub( str, "Goodbye London!", "Hello New York!" )
fp:close()
fp = io.open( fn, "w+" )
fp:write( str )
fp:close()
end