Bash 数组

11月 14, 2016 |

使用关联数组统计apache日志中每个IP出现的次数(实现分组计数,或者分组求和)

#/bin/bash
declare -A arr;
for ip in $(cut -f 1 -d ' ' apache_qxu1606530096_20200620.log)
do
let arr["$ip"]=arr["$ip"]+1;
done
for x in ${!arr[@]}
do
echo "$x|${arr["$x"]}";
done

Posted in: Linux

Comments are closed.