#! /bin/bash
declare -A mapUser
while read LINE
do
logstr=$LINE;
userstr=`echo $logstr | awk -F "," '{ print $3}'`;
useropt=`echo $logstr | awk -F "," '{ print $4}'`;
param=`echo ${mapUser[$userstr]}`;
if [ "$useropt" == " operator=D" ];then
if [ ! -n "$param" ];then
mapUser[$userstr]=1
#echo "is null"
else
count=$(($param+1))
mapUser[$userstr]=$count
fi
fi
#echo $useropt;
#echo $userstr;
done < /usr/local/shell/userlog.txt
echo ${mapUser[@]}
echo ${!mapUser[@]}
~
细节没有处理,比如字符串空格处理,日志格式:
loginTime=2014-09-18 09:47:09, ip=46.135.145.154, user=3, operator=C, model=update user, statu=fail