| 1 |
#! /usr/bin/env bash |
| 2 |
|
| 3 |
# $Header: /u/gcmpack/MITgcm_contrib/jmc_script/extract_MON,v 1.1 2020/11/09 17:36:04 jmc Exp $ |
| 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 |
#---------------------------------------------------------- |
| 21 |
touch $output $tmpfil |
| 22 |
sed -n '/%MON/p' $1 | sed 's/(PID\.TID 000.\.000.) //g' >> $tmpfil |
| 23 |
#egrep '%MON|cg2d_init_res' $1 | sed 's/(PID\.TID 000.\.000.) //g' >> $tmpfil |
| 24 |
|
| 25 |
if test $n1 = 0 |
| 26 |
then |
| 27 |
echo ' take all lines' |
| 28 |
cat $tmpfil >> $output |
| 29 |
rm -f $tmpfil |
| 30 |
exit |
| 31 |
fi |
| 32 |
|
| 33 |
if [ $n1 -lt 0 ] |
| 34 |
then |
| 35 |
#- used to add the 1rst "Shap global diagnostic" (if test $n1 = -1): |
| 36 |
# select lines starting just after the -$n1 ^th line that match the last record |
| 37 |
n0=`expr 0 - $n1` |
| 38 |
line=`tail -1 $tmpfil | sed 's/= .....................//g'` |
| 39 |
num0=`sed -n "/$line/=" $tmpfil | sed -n "$n0 p"` |
| 40 |
num1=`expr $num0 + 1` |
| 41 |
else |
| 42 |
# select lines starting at the $n1 ^th "time_tsnumber" record |
| 43 |
num1=`sed -n '/%MON time_tsnumber/=' $tmpfil | sed -n "$n1 p"` |
| 44 |
fi |
| 45 |
echo ' start at line' $num1 ' :' |
| 46 |
sed -n "$num1 p" $tmpfil |
| 47 |
|
| 48 |
sed -n "$num1,$ p" $tmpfil >> $output |
| 49 |
rm -f $tmpfil |
| 50 |
exit |