Skip to content

Instantly share code, notes, and snippets.

@danopia
Created September 10, 2020 14:48
Show Gist options
  • Save danopia/ab549db45c0a0604c9b242ac093b00d3 to your computer and use it in GitHub Desktop.
Save danopia/ab549db45c0a0604c9b242ac093b00d3 to your computer and use it in GitHub Desktop.
Small Deno tools
// In a Unix pipe, accepts 'tableized' input with many spaces between fields,
// and outputs the data as a traditional CSV.
// Does not handle input where fields contain their own spaces.
import { BufReader, BufWriter } from "https://deno.land/[email protected]/io/bufio.ts";
import { TextProtoReader } from "https://deno.land/[email protected]/textproto/mod.ts";
const input = new TextProtoReader(new BufReader(Deno.stdin));
while (true) {
const line = await input.readLine();
if (line === null) {
break;
} else {
console.log(line.replace(/ +/g, ','));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment