-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind-max-depth.sh
47 lines (40 loc) · 963 Bytes
/
find-max-depth.sh
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
#
while getopts 'xh' opt; do
case "$opt" in
x)
set -x
;;
?|h)
cat - <<EOF
NAME
$(basename $0) - get the depth of the deepest node in the parse tree
SYNOPSIS
$(basename $0) ([-x | -h])* [files]
DESCRIPTION
This script must be run under Linux Bash or Windows MSYS2 Bash or Windows WSL Linux.
OPTIONS
-h
Output this help message.
-x
Execute "set -x" to debug script.
EXAMPLE USAGE
EOF
exit 0
;;
esac
done
shift $((OPTIND - 1))
files=("$@")
temp=`mktemp`
if [ ${#files[@]} -gt 0 ]
then
trparse -l ${files[@]} > $temp
else
cat - > $temp
fi
# cat $temp | trxgrep ' //*[not(*) and count(ancestor::*) = max(//*[not(*)]/count(ancestor::*))]/(self::node|..)' | trcaret
cat $temp | trxgrep ' for $i in max(//*[not(*)]/count(ancestor::*))
return
(for $j in (//*[not(*) and count(ancestor::*) = $i])
return $j/(self::node|..))' | trcaret
rm -f $temp