Repository navigation
Expand file tree
/
Copy pathCODING__ReportControlWordUsage.sh
More file actions
85 lines (68 loc) · 1.81 KB
/
Copy pathCODING__ReportControlWordUsage.sh
File metadata and controls
85 lines (68 loc) · 1.81 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
76
77
78
79
80
81
82
83
#!/bin/bash
####################################################################################################
###
### $Id: CODING__ReportControlWordUsage.sh,v 1.1 2024/09/11 20:50:34 root Exp $
###
### Report scripts where specified flow-control words have been used, and count of such files.
###
####################################################################################################
BASE=$(basename "$0" ".sh" )
TMP=/tmp/${BASE}.tmp
flowcontrol="if for while until case"
cd $Oasis/bin
find . -mindepth 1 -maxdepth 1 -name '*.sh' -print 2>>/dev/null | cut -c3- | sort >"${TMP}"
count=$(wc -l "${TMP}" | awk '{ print $1 }' )
rm -f "${TMP}.locate."*
rm -f "${BASE}.locate"
while read line
do
printf " [${count}] '${line}' ...\n" >&2
freq="${line}"
for control in ${flowcontrol}
do
rm -f "${TMP}.raw"
grep --with-filename "${control} " "${line}" >"${TMP}.raw"
if [ -s "${TMP}.raw" ]
then
freq="${freq}|$(wc -l "${TMP}.raw" | awk '{ print $1 }' )"
cat "${TMP}.raw" >>"${TMP}.locate.${control}"
else
freq="${freq}|0"
fi
done
testor="$(echo "${freq}" | grep '|' )"
if [ -n "${testor}" ]
then
echo "${freq}" | awk -v flow="dum ${flowcontrol}" 'BEGIN{
split(flow, cntl) ;
}{
n=split($0, vals, "|") ;
det=""
for( i=2 ; i<=n ; i++ ){
if( vals[i] != 0 ){
det=sprintf("%s\n\t%3d %s", det, vals[i], cntl[i] ) ;
} ;
} ;
if( det != "" ){
printf("\n%s%s\n", vals[1], det ) ;
} ;
exit ;
}'
fi
count=$(expr ${count} - 1 )
done <"${TMP}" >"${BASE}.locate"
echo ""
for control in ${flowcontrol}
do
if [ -s "${TMP}.locate.${control}" ]
then
mv "${TMP}.locate.${control}" "${BASE}.locate.${control}"
ls -l "${BASE}.locate.${control}"
wc -l "${BASE}.locate.${control}"
echo ""
fi
done
mv ${TMP} ${BASE}.scanned
exit 0
exit 0
exit 0