#!/bin/bash

tip=0
tlink=0

tip=`cat ./nowcoder.txt|grep tcp|grep :3306|awk '{print $5}'|awk -F":" '{print $1}'|sort | uniq -c|wc -l`
echo "TOTAL_IP "$tip

tele=""
tsum=0
for ele in `cat ./nowcoder.txt|grep :3306|awk '{print $NF}'|sort`
do
        if [[ $tele == "" ]];then
                tele=$ele
        fi
        if [[ $tele != $ele ]];then
                echo $tele" "$tsum
                tele=$ele
                tsum=1
        else
                tsum=$((tsum+1))
        fi
done
echo $tele" "$tsum

tlink=`cat ./nowcoder.txt |grep :3306|wc -l`
echo "TOTAL_LINK "$tlink

题解大部分只考虑了只有ESTABLISTHED状态,我的解可以在多种状态下仍然能正确输出。