話說同僚發給我一道shell 程式設計題,要求根據原始資料統計出每個qq号綁定哪些手機号及幾個手機号,原始資料如下(qq号:手機号):
11235334:13443253456
11235335:13443253457
11235336:13443253458
11235333:13443253458
11235336:13443253459
11235334:13443253452
下面是我寫的shell:
#!/bin/bash
line=$(cat hb | awk -F: '{print $1}' | sort | uniq |wc -l)
for ((i=1;i<=$line;i=i+1))
do
line1=$(cat hb | awk -F: '{print $1}' | sort | uniq|sed -n ''$i'p')
echo "-----------"
echo [$line1]
echo " "
grep $line1 hb|awk -F: '{print $2}'
grep $line1 hb|awk -F: '{print $2}'| wc -l
done
執行結果:
-----------
[11235333]
13443253458
1
[11235334]
13443253456
13443253452
2
[11235335]
13443253457
[11235336]
13443253459
本文轉自hb_fukua 51CTO部落格,原文連結:http://blog.51cto.com/2804976/526686,如需轉載請自行聯系原作者