| 1 | #! /usr/bin/env bash | 
| 2 |  | 
| 3 | # $Header: $ | 
| 4 | # $Name: $ | 
| 5 |  | 
| 6 | tmpfil=TTT.$$ | 
| 7 | if [ $# -le 1 ] | 
| 8 | then | 
| 9 | echo 'Usage: '`basename $0`' file_input file_output [n]' | 
| 10 | echo '  ==> extract lines with "MON" out off file_input to file_output' | 
| 11 | echo '      start at the 1rst [or n^th] "%MON time_tsnumber"' | 
| 12 | echo '   or (n<0) after the (-n)^th line that match the last record' | 
| 13 | exit | 
| 14 | else | 
| 15 | if test $# = 2 ; then n1=1 ; else n1=$3 ; fi | 
| 16 | file=$1 ; output=$2 ; | 
| 17 | echo '  ==> extract lines with "MON" out off file='$file ' to '$output | 
| 18 | fi | 
| 19 | #---------------------------------------------------------- | 
| 20 | touch $output $tmpfil | 
| 21 | sed -n '/%MON/p' $1 | sed 's/(PID\.TID 000.\.000.) //g' >> $tmpfil | 
| 22 | #egrep '%MON|cg2d_init_res' $1 | sed 's/(PID\.TID 000.\.000.) //g' >> $tmpfil | 
| 23 |  | 
| 24 | if test $n1 = 0 | 
| 25 | then | 
| 26 | echo '      take all lines' | 
| 27 | cat $tmpfil >> $output | 
| 28 | rm -f $tmpfil | 
| 29 | exit | 
| 30 | fi | 
| 31 |  | 
| 32 | if [ $n1 -lt 0 ] | 
| 33 | then | 
| 34 | #- used to add the 1rst "Shap global diagnostic" (if test $n1 = -1): | 
| 35 | #  select lines starting just after the -$n1 ^th line that match the last record | 
| 36 | n0=`expr 0 - $n1` | 
| 37 | line=`tail -1 $tmpfil | sed 's/= .....................//g'` | 
| 38 | num0=`sed -n "/$line/=" $tmpfil | sed -n "$n0 p"` | 
| 39 | num1=`expr $num0 + 1` | 
| 40 | else | 
| 41 | #  select lines starting at the $n1 ^th "time_tsnumber" record | 
| 42 | num1=`sed -n '/%MON time_tsnumber/=' $tmpfil | sed -n "$n1 p"` | 
| 43 | fi | 
| 44 | echo '      start at line' $num1 ' :' | 
| 45 | sed -n "$num1 p" $tmpfil | 
| 46 |  | 
| 47 | sed -n "$num1,$ p" $tmpfil >> $output | 
| 48 | rm -f $tmpfil | 
| 49 | exit |