我有如下文件,格式如下:
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz,NVIDIA GeForce 9500 GT @ 494.48798
Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz,NVIDIA GeForce 9500 GT @ 494.48798
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
我怎么统计以逗号分隔的共有相同的第一列共有多少行和相同的第二列列共有多少行?
比如上面的结果应为:
cpu类型
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+:4
NVIDIA GeForce 9500 GT @ 494.48798:6
Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz:2
[root@Greendays lianshou]# awk -F"," '{print $1}' a | sort | uniq -c
4 AMD Athlon(tm) 64 X2 Dual Core Processor 5000+
2 Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
[root@Greendays lianshou]# awk -F"," '{print $2}' a | sort | uniq -c
6 NVIDIA GeForce 9500 GT @ 494.48798
[root@Greendays lianshou]# cat a
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz,NVIDIA GeForce 9500 GT @ 494.48798
Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz,NVIDIA GeForce 9500 GT @ 494.48798
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+,NVIDIA GeForce 9500 GT @ 494.48798
[root@Greendays lianshou]# awk -F "," '{a[$1]++;b[$2]++}END{for (i in a) print i":"a[i];for (j in b) print j":"b[j]}' a
Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz:2
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+:4
NVIDIA GeForce 9500 GT @ 494.48798:6
[root@Greendays lianshou]# awk -F "," '{a[$1]++;b[$2]++}END{for (i in a) print i":"a[i];for (j in b) print j":"b[j]}' a
Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz:2
AMD Athlon(tm) 64 X2 Dual Core Processor 5000+:4
NVIDIA GeForce 9500 GT @ 494.48798:6
阅读(734) | 评论(0) | 转发(0) |