I would like to know if it is possible to open a file for both reading and writing.
f = assert(io.open("words", "r"))
t = f:read("a")
t = string.gsub(t, "Bad", "Good")
f = assert(io.open("words", "w"))
f:write(t)
f:close()
The above code seems to be working as expected. Sometimes what seems to work is not valid. For example, in some Unix pipelines, data is swallowed by one of the commands in an unintended fashion.