Files
fumen-measure-analyze/scripts/clean_csv.ts
2026-04-20 00:21:53 +09:00

30 lines
923 B
TypeScript

import { readFile, writeFile } from "node:fs/promises";
async function cleanCsv() {
const filePath = "measure.csv";
try {
const content = await readFile(filePath, "utf-8");
const lines = content.split("\n");
if (lines.length === 0) return;
const cleanedLines = lines.map(line => {
if (!line.trim()) return "";
// Basic CSV split (Note: does not handle quoted commas,
// but based on our previous read, the columns we need are early and simple)
const cols = line.split(",");
// Indices: 상수(1), songno(3), diff(4) -> 0-based: 1, 3, 4
const selected = [cols[1], cols[3], cols[4]];
return selected.join(",");
}).filter(line => line !== "");
await writeFile(filePath, cleanedLines.join("\n"));
console.log("measure.csv cleaned successfully.");
} catch (error) {
console.error("Error cleaning CSV:", error);
}
}
cleanCsv();