#!/usr/bin/lua local fil = io.open(arg[1] or "/tmp/file/not/found.txt", "rb") if not fil then io.stderr:write("Error, failed to open file.\n") io.stderr:flush() os.exit(1) end while true do local nextl = fil:read("*l") if nextl == nil then break end local name, tag_type, deadZone, alarmCode, reasonCode, severity, condition, value, valid = string.match(nextl, '("[^{}%s,]+")%s*,%s*([^{}%s,]+)%s*,%s*([^{}%s,]+)%s*,%s*{([^{}%s,]+)%s*,%s*([^{}%s,]+)%s*,%s*([^{}%s,]+)%s*,%s*([^{}%s,]+)%s*,%s*([^{}%s,]+)[%s{},]+([^{}%s,]+)') if not name then io.stdout:write(nextl) else io.stdout:write(string.format(' {"name":%s, "tag_type":"%s", "deadZone":%s, "list_alarm_info":{"alarmCode":%s, "reasonCode":%s,\n "severity":"%s", "condition":"%s", "value":%s, "valid": %s}},\n', name, tag_type, deadZone, alarmCode, reasonCode, severity, condition, value, valid)) end io.stdout:write("\n") io.stdout:flush() end fil:close() os.exit(0)