Hi I’ve got a log file containing trace routes and pings.
Ive seperated these by using
if (scanner.nextLine ().startsWith ("64 bytes"){}
so I can work with just the pings for now.
All I’m interested in from the ping is time=XX
example data line =
64 bytes from ziva.zarnet.ac.zw (209.88.89.132): icmp_seq=119 ttl=46 time=199 ms
I have been reading other peoples similar questions and I’m not sure how to apply to mine.
I literally need just the numbers as I will be putting them into a csv file so I can make a graph of the data.
edit: Using robins solution I’m now having my pings being spurted out on screen, except it’s doing every other and missing the first.
while (scanner.hasNextLine ()) {
//take only pings.
if (scanner.nextLine ().startsWith ("64 bytes")){
String line = scanner.nextLine ();
String pingAsString = line.substring (line.lastIndexOf ("=") + 1, (line.length () - "ms".length ()));
Double ping = Double.valueOf (pingAsString);
System.out.println ("PING AS STRING = "+ping);
}
}
OK SORTED. THAT JUST NEEDED TO MOVE LINE ASSIGNMENT. CAPS. but made it clear. 😀
Or you can just use the available methods on
Stringif you do not want to perform reg-ex magic