 import typealias Categorizer.History
 import func CSV.parse
 
+public struct StderrOutputStream: TextOutputStream {
+    public mutating func write(_ string: String) { fputs(string, stderr) }
+}
+public var errStream = StderrOutputStream()
+
 let settings = parseSettings()
 
 let tokens: [Token]
 do {
     tokens = try parseLedger(filename: (settings.trainFile as NSString).expandingTildeInPath)
 } catch {
-    print("Could not parse ledger file: \(error)")
+    print("Could not parse ledger file: \(error)", to: &errStream)
     exit(1)
 }
 let transactions = tokens.flatMap { (token: Token) -> Transaction? in

    }

    guard let date = csvDateFormatter.date(from: row[settings.csvDateColumn]) else {
        print("Could not parse date \(row[settings.csvDateColumn])")
        exit(1)
    }


        let csv = note.substring(from: note.index(note.startIndex, offsetBy: 6))
        guard let row = (try? CSV.parse(csv.data(using: .utf8)!))?.first else { continue }
        guard row.count >= minimalColumnCount else {
            print(transaction, to: &errStream)
            print("Found a transaction with \(row.count) columns, at least \(minimalColumnCount) expected", to: &errStream)
            continue
        }
        let tokens = extractTokens(row: row)
