You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kamailio/scripts/filter_log.sh

59 lines
691 B

#!/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"