Created
January 30, 2023 19:35
-
-
Save mioe/79cfbc40b964a4ccab34e76ba7ffb812 to your computer and use it in GitHub Desktop.
simple parse csv via Deno π¦
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
import { parse as parseCsv } from 'https://deno.land/[email protected]/encoding/csv.ts' | |
const data = await parseCsv(await Deno.readTextFile('data.csv')) | |
const query = await parseCsv(await Deno.readTextFile('query.csv')) | |
if (import.meta.main) { | |
const Q = query.flatMap((row) => row) | |
const INDEX = { | |
name: 1, | |
owner_id: 3, | |
} | |
const result = data.filter((row: any) => Q.includes(row[INDEX.owner_id])) | |
const formatted = result | |
.map((row: any) => [ | |
row[INDEX.owner_id], | |
'https://' + row[INDEX.name] + '.example.com', | |
]) | |
.map((row) => `${row[0]};${row[1]}`) | |
.join('\n') | |
await Deno.writeTextFile('./result.csv', formatted) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment