#!/bin/rc # tget: print log lines on a given time range rfork e flagfmt='m,d,h' args='time0 time1 [file...]' t0=0 t1=0 sopt=() fn usage{ aux/usage exit usage } fn isint{ echo $1 | grep -s '^[0-9]+$' } fn beg{ sed 1q $1 | awk '{ print $1 }' } fn end{ tail -1 $1 | awk '{ print $1 }' } fn fileok{ file=$1 beg=`{beg $file} end=`{end $file} stat='' if(! isint $beg || ! isint $end){ echo $file not a log >[1=2] stat=no } if not if(test ($t1 -ne 0 -a $t1 -lt $beg) -o $t0 -gt $end){ echo $file not in range >[1=2] stat=no } status=$stat } fn get{ awk ' BEGIN { t0 = '$t0' t1 = '$t1' } { if($1 >= t0 && (!t1 || $1 <= t1)) print } ' $* } if(! ifs=() eval `{aux/getflags $*} || ~ $#* (0 1)) usage for(i in (m d h)) if(eval '~ $flag'$i' 1') sopt=-$i if(! ~ $1 -){ t0=`{sec $sopt $1} if(! ~ $status '') usage } if(! ~ $2 -){ t1=`{sec $sopt $2} if(! ~ $status '') usage } shift 2 switch($#*){ case 0 get /fd/0 case * for(f) if(fileok $f){ if(! ~ $#* 1) echo $f: get $f } }