1// csv.d
2
3void main() {
4
5 import std;
6
7
8 File[string] outputFiles;
9
10 auto inputFile = File("input.csv");
11
12 auto lines = inputFile.byLine;
13
14 lines.popFront; // skip header
15
16
17 foreach (line; lines) {
18
19 const name = line.splitter(',').front;
20
21 // open output file if not already open in append mode
22
23 if (name !in outputFiles) {
24
25 outputFiles[name] = File(name ~ ".csv", "a");
26 }
27
28 outputFiles[name].writeln(line);
29 }
30}