用Lua脚本来扫描一个日志文件,找出里面的关键字

要求用Lua脚本来扫描一个日志文件,找出里面的关键字Error和Waring。
由于没有学过lua,希望能回答得具体点,谢谢

逐行读取进行匹配
local file = io.open("log.txt","r") --打开log
for l in file:lines() do --逐行读取
if string.match(l,"error") then --如果存在字符串‘error’
print(l) --输出
end
end
file:close()
温馨提示:答案为网友推荐,仅供参考
相似回答