Skip to content

Instantly share code, notes, and snippets.

@CarsonSlovoka
Created May 26, 2025 07:02
Show Gist options
  • Save CarsonSlovoka/cf02354a9b506141ebc1dc39712caa7f to your computer and use it in GitHub Desktop.
Save CarsonSlovoka/cf02354a9b506141ebc1dc39712caa7f to your computer and use it in GitHub Desktop.
-- USAGE:
-- CSV_PATH=temp.csv lua5.1 read_csv.lua
local csv_path = os.getenv("CSV_PATH") or "your_file.csv"
local file = io.open(csv_path, "r")
if not file then
print("無法打開文件: " .. csv_path)
return
end
-- local counter = 0
local header = file:read("*line") -- for skip header
local row = {}
for line in file:lines() do
if #line ~= 0 then
local col = {}
for field in line:gmatch("[^,]+") do
table.insert(col, field)
end
table.insert(row, col)
-- counter = counter + 1
end
end
file:close()
print(row[2][3])
-- print("Total count: " .. counter)
print("Total count: " .. #row)
tilte 描述 number
test 中文 9
foo 55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment