Example: File Processing
A script that parses a log file and extracts formatted records:
use file
use regex
let logFile = "app.log"
if not file.exists(logFile)
# Seed dummy log
file.write(logFile, "[INFO] Started\n[ERROR] DB Connection failed\n[INFO] Retrying\n")
end
let pattern = regex.compile("\\[(INFO|ERROR)\\] (.*)")
let lines = file.readLines(logFile)
for idx, line in enumerate(lines)
let match = pattern.search(line)
if !isNull(match)
let level = match.group(1)
let msg = match.group(2)
print("Line ${idx + 1}: [${level}] - Message: ${msg}")
end
end