Created
April 29, 2019 08:29
-
-
Save nanpuyue/b423a71013df21a6a41d3e97389657eb 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::env::args; | |
use std::fs::File; | |
use std::io::{BufRead, BufReader}; | |
use std::str::FromStr; | |
fn main() { | |
let mut args = args(); | |
if args.len() == 3 { | |
args.next(); | |
let interval = u32::from_str(&args.next().unwrap()).unwrap(); | |
let file = File::open(&args.next().unwrap()).unwrap(); | |
let file = BufReader::new(file); | |
let mut end = 0; | |
for line in file.lines() { | |
if let Ok(s) = line { | |
let mut s = s.split_whitespace().collect::<Vec<&str>>(); | |
let data = s[2]; | |
s = s[0].split('-').collect(); | |
let start = u32::from_str(s[0]).unwrap(); | |
if start - end > interval { | |
print!("\n{}", data); | |
} else { | |
print!("{}", data); | |
} | |
end = u32::from_str(s[1]).unwrap(); | |
} | |
} | |
} | |
println!(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment