Last active
July 4, 2017 17:55
-
-
Save d33tah/04bf11ff94925f0c5e18b8e2b15fd246 to your computer and use it in GitHub Desktop.
This file contains 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
use std::error::Error; | |
use std::process; | |
use std::fs::File; | |
use std::io; | |
use std::io::Write; | |
use std::io::BufWriter; | |
extern crate csv; | |
fn run() -> Result<(), Box<Error>> { | |
let mut open_files: Vec<BufWriter<File>> = Vec::new(); | |
let mut max_file = 0; | |
let mut rdr = csv::ReaderBuilder::new().has_headers(false).from_reader(io::stdin()); | |
for result in rdr.records() { | |
let record = result?; | |
for i in max_file..record.len() { | |
open_files.push(BufWriter::new(File::create(i.to_string())?)); | |
} | |
max_file = record.len(); | |
for (i, item) in record.iter().enumerate() { | |
open_files[i].write_fmt(format_args!("{}\n", &record[i]))?; | |
} | |
} | |
Ok(()) | |
} | |
fn main() { | |
if let Err(err) = run() { | |
println!("{}", err); | |
process::exit(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment