I am writing a file from shell script and reading that file from java and prints % in jsp page.. Here's the file :
0K .......... .......... .......... .......... .......... 0% 6.93 MB/s
50K .......... .......... .......... .......... .......... 0% 1.75 MB/s
100K .......... .......... .......... .......... .......... 0% 3.78 MB/s
150K .......... .......... .......... .......... .......... 1% 1.93 MB/s
200K .......... .......... .......... .......... .......... 1% 3.66 MB/s
250K .......... .......... .......... .......... .......... 2% 7.84 MB/s
300K .......... .......... .......... .......... .......... 2% 3.65 MB/s
350K .......... .......... .......... .......... .......... 3% 2.45 MB/s
Here's the code to get pertucular value from file :
while((line = file.readLine()) != null) {
int li = line.lastIndexOf("%");
if(li > 0)
progress = Integer.parseInt(line.substring(li - 3, li).trim());
}
Now the file format has been changed to below format :
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 164M 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 164M 0 272k 0 0 117k 0 0:23:54 0:00:02 0:23:52 303k
0 164M 0 624k 0 0 186k 0 0:15:04 0:00:03 0:15:01 322k
0 164M 0 960k 0 0 221k 0 0:12:41 0:00:04 0:12:37 328k
0 164M 0 1296k 0 0 242k 0 0:11:33 0:00:05 0:11:28 331k
0 164M 0 1632k 0 0 258k 0 0:10:52 0:00:06 0:10:46 333k
1 164M 1 1968k 0 0 267k 0 0:10:28 0:00:07 0:10:21 337k
1 164M 1 2304k 0 0 276k 0 0:10:08 0:00:08 0:10:00 337k
1 164M 1 2656k 0 0 283k 0 0:09:52 0:00:09 0:09:43 338k
1 164M 1 2992k 0 0 289k 0 0:09:41 0:00:10 0:09:31 339k
1 164M 1 3328k 0 0 293k 0 0:09:32 0:00:11 0:09:21 339k
2 164M 2 3680k 0 0 297k 0 0:09:25 0:00:12 0:09:13 341k
2 164M 2 4016k 0 0 300k 0 0:09:19 0:00:13 0:09:06 341k
2 164M 2 4352k 0 0 303k 0 0:09:14 0:00:14 0:09:00 340k
Without changing much I just want to perform same operation (see code) to get the value of column 1 i.e : % value.
How to modify the above code or is there any method (like lastIndexOf) that will have the first's columns value???