File: filter_log.sh

package info (click to toggle)
kamailio 5.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 68,332 kB
  • sloc: ansic: 744,091; xml: 196,848; cpp: 14,471; makefile: 8,859; sh: 8,814; sql: 7,844; yacc: 3,863; perl: 2,955; python: 2,710; java: 449; javascript: 269; php: 258; ruby: 225; cs: 40; awk: 27
file content (58 lines) | stat: -rwxr-xr-x 691 bytes parent folder | download | duplicates (9)
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
#!/bin/sh
#
# $Id$
#
# tool for filtering SIP messages from log by a RegExp
#
# Example of use: ./filter_msg.sh /var/log/sip/sip.1056844800 'CallId: abc'
#


#####################

usage()
{
	echo "Usage: $0 <filename> <RegExp>"
}

if [ "$#" -ne 2 ] ; then
	usage
	exit
fi

AWK_PG='
BEGIN {
	IGNORECASE=1;
	line=0;
	msg_match=0;
}

/^#$/ {
	line=0
	msg_match=0
	next
}

msg_match==1 {
	print
	next
}

{ 
	if (match($0, RE)) {
		msg_match=1;
		# dump all accumulated lines here
		for (i=1; i<=line; i++) print buffer[i];
		print
		next
	}
	# there are still chances for a match in following lines;
	# keep buffering this request
	line++
	buffer[line]=$0
}

'


cat $1 | awk "$AWK_PG" RE="$2"