Created
May 26, 2025 07:02
-
-
Save CarsonSlovoka/cf02354a9b506141ebc1dc39712caa7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tilte | 描述 | number | |
---|---|---|---|
test | 中文 | 9 | |
foo | 文 | 55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment