Skip to content

Instantly share code, notes, and snippets.

@birkenfeld
Created February 10, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save birkenfeld/fb4ec61ec70f781b93f1 to your computer and use it in GitHub Desktop.
Save birkenfeld/fb4ec61ec70f781b93f1 to your computer and use it in GitHub Desktop.
use std::io::{self, BufReader, BufWriter};
use std::io::prelude::*;
use std::fs::File;
fn main() {
let reader = io::stdin();
for line in reader.lock().lines() {
let path = line.unwrap();
let tmp_filename = path.clone() + "Leitner_2009R2_CompleteExport.txt";
let f = File::open(tmp_filename).unwrap();
let f = BufReader::new(f);
let mut new_f = None;
for line2 in f.lines() {
let mut curr_line = line2.unwrap_or("".into());
println!("{}", curr_line);
if curr_line.len() > 6 && &curr_line[..6] == "OBJECT" {
let new_name = curr_line.replace("/", "_");
let tmp_curr_filename = path.clone() + &new_name + ".txt";
let curr_file = File::create(tmp_curr_filename).unwrap();
new_f = Some(BufWriter::new(curr_file));
}
if let Some(nf) = new_f.as_mut() {
curr_line.push('\n');
nf.write(curr_line.as_bytes()).unwrap();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment