-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix-sections.sh
63 lines (58 loc) · 2 KB
/
fix-sections.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
CTR1=0
CTR2=0
CTR3=0
CTR4=0
CTR5=0
CUR_LVL=1
PREV_LVL=1
level_decrease() {
for i in $(seq $PREV_LVL -1 $(($CUR_LVL+1))); do
export CTR$i=0
done
}
while IFS= read -r line; do
if ( echo "$line" | grep -e "^--\[.*\]" >/dev/null ); then
CUR_LVL=1
if (( $CUR_LVL < $PREV_LVL )); then
level_decrease
fi
PREV_LVL=1
CTR1=$(($CTR1 + 1))
echo "$line" | sed "s/^--\[.*\]/--[$CTR1]/"
elif ( echo "$line" | grep -e "^----\[.*\]" >/dev/null ); then
CUR_LVL=2
if (( $CUR_LVL < $PREV_LVL )); then
level_decrease
fi
PREV_LVL=2
CTR2=$(($CTR2 + 1))
echo "$line" | sed "s/^----\[.*\]/----[$CTR1.$CTR2]/"
elif ( echo "$line" | grep -e "^------\[.*\]" >/dev/null ); then
CUR_LVL=3
if (( $CUR_LVL < $PREV_LVL )); then
level_decrease
fi
PREV_LVL=3
CTR3=$(($CTR3 + 1))
echo "$line" | sed "s/^------\[.*\]/------[$CTR1.$CTR2.$CTR3]/"
elif ( echo "$line" | grep -e "^--------\[.*\]" >/dev/null ); then
CUR_LVL=4
if (( $CUR_LVL < $PREV_LVL )); then
level_decrease
fi
PREV_LVL=4
CTR4=$(($CTR4 + 1))
echo "$line" | sed "s/^--------\[.*\]/--------[$CTR1.$CTR2.$CTR3.$CTR4]/"
elif ( echo "$line" | grep -e "^----------\[.*\]" >/dev/null ); then
CUR_LVL=5
if (( $CUR_LVL < $PREV_LVL )); then
level_decrease
fi
PREV_LVL=5
CTR5=$(($CTR5 + 1))
echo "$line" | sed "s/^----------\[.*\]/----------[$CTR1.$CTR2.$CTR3.$CTR4.$CTR5]/"
else
echo "$line"
fi
done < $1