/[MITgcm]/MITgcm_contrib/jmc_script/mod
ViewVC logotype

Annotation of /MITgcm_contrib/jmc_script/mod

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Wed Jul 19 14:04:48 2023 UTC (23 months, 3 weeks ago) by jmc
Branch: MAIN
CVS Tags: HEAD
add short script that I use to perform automatic substitution in src code

1 jmc 1.1 #! /usr/bin/env bash
2    
3     # $Header: /u/gcmpack/MITgcm_contrib/jmc_script/tst_2+2_cpl,v 1.15 2022/03/17 20:01:59 jmc Exp $
4     # $Name: $
5    
6     tmpfil='TTT.'$$
7     if test $# = 0 -o "x$1" = 'x-h' ; then
8     echo 'Usage: '`basename $0`' [-s sfile][-b][-f Action] list_of_file_to_process'
9     echo ' --> : apply modifications using sed script file "sfile", default: "mod.sed"'
10     echo ' -b : remove double blank lines (keep only 1 blank)'
11     echo ' -f : always do {Action} without asking, Action in: Y,I,K,S,N,E'
12     echo ' Y/I/K=apply, I=+confirm, K=+keep_date; S=save_to ".modif"; N=no; E=N+rm'
13     echo ' -h : print this message and exit'
14     exit
15     fi
16     sfile=
17     rmDblBlk=0
18     askresp='Y' ; resp='Y'
19     if test $1 = '-b' ; then rmDblBlk=1 ; shift ; fi
20     if test $1 = '-s' ; then sfile=$2 ; shift ; shift ; fi
21     if test $1 = '-b' ; then rmDblBlk=1 ; shift ; fi
22     if test $1 = '-f' ; then
23     case $2 in
24     "Y"|"I"|"K"|"S"|"N"|"E") askresp='N' ; resp=$2 ;;
25     *) echo "option '-f' with invalid argument {Action}='$2'" ; exit 1 ;;
26     esac
27     shift ; shift
28     fi
29     if test $1 = '-b' ; then rmDblBlk=1 ; shift ; fi
30    
31     liste=$*
32     thisfile=`basename $0`
33     if test "x$sfile" = x ; then sfile=${thisfile}.sed ; fi
34     if test -f $sfile
35     then
36     echo "modification file =" $sfile ":"
37     cat $sfile
38     sleep 1
39     for xx in $liste
40     do
41     rm -f $tmpfil
42     if test $rmDblBlk = 1 ; then
43     sed -f $sfile $xx | cat -s > $tmpfil
44     else
45     sed -f $sfile $xx > $tmpfil
46     fi
47     echo diff $xx $tmpfil
48     diff $xx $tmpfil
49     yy=$?
50     if test $yy != '0'
51     then
52     if test $askresp = 'Y'
53     then
54     echo "Apply changes ? (y/i/s=sav,k=y+keep_date,n=no,e=n+rm) ->" $xx 1>&2
55     read resp
56     else
57     echo "Apply changes ->" $xx
58     fi
59     case $resp in
60     "k"|"K") touch -r $xx $tmpfil ; mv -f $tmpfil $xx ;;
61     "y"|"Y") mv -f $tmpfil $xx ;;
62     "i"|"I") mv -i $tmpfil $xx ;;
63     "s"|"S") mv -f $tmpfil $xx.modif ;;
64     "e"|"E") rm -f $tmpfil ;;
65     *) ;;
66     esac
67     else
68     echo "No changes in :" $xx
69     rm -f $tmpfil
70     fi
71     done
72     #rm -f $tmpfil
73     else
74     echo "no file $sfile"
75     fi
76     exit

  ViewVC Help
Powered by ViewVC 1.1.22