1. grep查找,awk分割两次,排序,计数,排序,打印
grep '3306.*ESTABLISHED' nowcoder.txt | awk '{print $5}' | awk -F ':' '{print $1}' | sort | uniq -c | sort -nr | awk '{print $1, $2}'
2. grep查找,awk分割,sed将:3306替换为空,排序,计数,排序,打印
grep '3306.*ESTABLISHED' nowcoder.txt | awk '{print $5}' | sed 's/:3306//g' | sort | uniq -c | sort -nr | awk '{print $1, $2}'
3. awk查找,分割两次,排序,计数,排序,打印
awk '/3306.*ESTABLISHED/ {print $5}' nowcoder.txt | awk -F ':' '{print $1}' | sort | uniq -c | sort -nr | awk '{print $1, $2}'
4. awk查找,分割,sed将:3306替换为空,排序,计数,排序,打印
awk '/3306.*ESTABLISHED/ {print $5}' nowcoder.txt | sed 's/:3306//g' | sort | uniq -c | sort -nr | awk '{print $1, $2}'
5. awk查找,substr子串,排序,计数,排序,打印
awk '/3306.*ESTABLISHED/ {print substr($5, 0, length($5) - 5)}' nowcoder.txt | sort | uniq -c | sort -nr | awk '{print $1, $2}'