Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2079404
  • 博文数量: 470
  • 博客积分: 10206
  • 博客等级: 上将
  • 技术积分: 5620
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-03 12:50
文章分类

全部博文(470)

文章存档

2012年(1)

2011年(18)

2010年(47)

2009年(404)

分类:

2009-04-15 09:07:48

我有如下文件,格式如下:
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) |
0

上一篇:rename 经典

下一篇:如果FS里含有"怎么写

给主人留下些什么吧!~~