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