Here is perl script , input file and output file
================
input file x6.txt
================
$ cat x6.txt
TIME : 00:00:00 00:06:00
TOTAL : 9947
RTT : 0.78 seconds
d,ghaslkghaslkghasglkahsgl
algjalkgjaklgjaklgjalkgjal
agljalkgjalkgalkjga
TIME : 00:06:00 00:12:00
TOTAL : 9123
RTT : 0.54 seconds
d,ghaslkghaslkghasglkahsgl
algjalkgjaklgjaklgjalkgjal
agljalkgjalkgalkjga
... <other data follows that is not important> ...
TIME : 00:12:00 00:18:00
TOTAL : 8547
RTT : 0.48 seconds
d,ghaslkghaslkghasglkahsgl
algjalkgjaklgjaklgjalkgjal
agljalkgjalkgalkjga
================
output file x6_out.txt
================
$ cat x6_out.txt
00:06:00 9947 0.78
00:12:00 9123 0.54
00:18:00 8547 0.48
================
source code
================
$ cat x6.pl
#!/usr/local/bin/perl5.002
#
# Parsing the following
# TIME : 00:00:00 00:06:00
# TOTAL : 9947
# RTT : 0.78 seconds
#
# output will be 00:06:00 9947 0.54
#----------------------
# Define input file
#----------------------
$sourceFile="x6.txt";
$TIME="";
$TOTAL="";
$RTT="";
#-------------------------
# Define output files
#-------------------------
$F00="x6_out.txt";
#----------------------
# Create File Handlers
#----------------------
open(IN,"$sourceFile");
open(OUTAA,">$F00");
select(OUTAA);
while(<IN>) {
if(/^TIME/) {
$myline=$_;
chop($myline);
($y1,$y2,$y3,$y4)=split(" +",$myline);
$TIME=$y4;
}
if(/^TOTAL/) {
$myline=$_;
chop($myline);
($x1,$x2)=split(":",$mylin
$TOTAL=$x2;
}
if(/^RTT/) {
$myline=$_;
chop($myline);
($e1,$e2,$e3)=split(" +",$myline);
$RTT=$e3;
print $TIME.$TOTAL." ".$RTT."\n" ;
}
}
close(IN);
close(OUTAA);
Is there any spaces before "TIME", "TOTAL" and "RTT" ?
I assume there is no spaces, that's why I put "^" at if condition
If there is spaces , you need to change if condition to include "^ *TOTOAL" , let me know
Main Topics
Browse All Topics





by: HamdyHassanPosted on 2006-09-29 at 06:16:50ID: 17626975
perl will be easy
if you want ksh/grep also can be done by looping on data_file and using variabes
var_time=`grep "^TIME" filename | cut -f2- -d":"`
.........
............
var_rtt=`grep "^RTT" filename | cut -f2- -d":"`
then you can echo $var_time $var_rit in way you want
Do you need help on perl or ksh/grep