-
Notifications
You must be signed in to change notification settings - Fork 1
/
label_line_wrap.sh
executable file
·56 lines (41 loc) · 1.33 KB
/
label_line_wrap.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
#!/bin/bash
# A little script to split the labels, some of which are very long, across
# multiple lines
#
# -- Copy file to make sure we don't overwrite the original by mistake...
NEWFILE=${1%.dot}_labelwrap.dot
cp $1 $NEWFILE
#
# -- What should the maximum line length be?
LINE_LEN=16
#
# -- Split apart so the labels start at column 0 on their on lines, like so:
#
# rule_920220 [label="920220\nURL encoding abuse in the request URI\nPhase 2"];
# becomes:
# rule_920220 [label="920220\n
#URL encoding abuse in the request URI
# \nPhase 2"];
sed -i -E 's/(.+\[label="[[:digit:]]+\\n)(.+)(\\nPhase .+)/\1\n\2\n\t\3/g' $NEWFILE
#
# -- Use Perl to add in the newlines
#
# Conditional: only if line starts with non-space char (leaves alone the
# non-label bits)
perl -i -pe 's/(.{'$LINE_LEN'}) (?=\S)/$1\\n/g if /^\S/' $NEWFILE
#
# -- Putting back together
# Step 1
# rule_920220 [label="920220\n
#URL encoding abuse in the request URI
# \nPhase 2"];
# becomes:
# rule_920220 [label="920220\nURL encoding abuse in the request URI
# \nPhase 2"];
sed -i -E ':a;N;$!ba;s/(label="[[:digit:]]+\\n)\n/\1/g' $NEWFILE
# Step 2
# rule_920220 [label="920220\nURL encoding abuse in the request URI
# \nPhase 2"];
# becomes:
# rule_920220 [label="920220\nURL encoding abuse in the request URI\nPhase 2"];
sed -i -E ':a;N;$!ba;s/\n\t(\\nPhase)/\1/g' $NEWFILE