Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1691803
  • 博文数量: 136
  • 博客积分: 10021
  • 博客等级: 上将
  • 技术积分: 3261
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-22 11:26
文章分类

全部博文(136)

文章存档

2010年(1)

2009年(26)

2008年(109)

我的朋友

分类: LINUX

2009-06-13 15:56:16

信息的处理,包括数据库信息的处理(SQL)和文本信息的处理。我对SQL比较熟悉,下面拿SQL和文本信息的处理对比一下:
 
#1. 查询所有的数据 - select * from ping;
 
[dwapp@dw_testdb yuechaotian]$ cat ping.txt 
64 bytes from 1.2.3.2: icmp_seq=0 ttl=60 time=0.655 ms
64 bytes from 1.22.3.2: icmp_seq=1 ttl=60 time=0.328 ms
64 bytes from 1.2.3.2: icmp_seq=2 ttl=60 time=0.292 ms
64 bytes from 1.22.3.2: icmp_seq=3 ttl=60 time=0.311 ms
64 bytes from 1.2.3.2: icmp_seq=4 ttl=60 time=0.316 ms
64 bytes from 1.2.3.2: icmp_seq=0 ttl=60 time=0.655 ms
64 bytes from 1.2.3.2: icmp_seq=0 ttl=60 time=0.655 ms
64 bytes from 1.22.3.2: icmp_seq=1 ttl=60 time=0.328 ms
64 bytes from 1.2.3.2: icmp_seq=2 ttl=60 time=0.292 ms
64 bytes from 1.22.3.2: icmp_seq=3 ttl=60 time=0.311 ms
64 bytes from 1.2.3.2: icmp_seq=4 ttl=60 time=0.316 ms
64 bytes from 1.22.3.2: icmp_seq=1 ttl=60 time=0.328 ms
64 bytes from 1.2.3.2: icmp_seq=2 ttl=60 time=0.292 ms
64 bytes from 1.22.3.2: icmp_seq=3 ttl=60 time=0.311 ms
64 bytes from 1.2.3.2: icmp_seq=4 ttl=60 time=0.316 ms
64 bytes from 1.22.3.2: icmp_seq=3 ttl=60 time=0.311 ms
64 bytes from 1.22.3.2: icmp_seq=3 ttl=60 time=0.311 ms
64 bytes from 1.2.3.2: icmp_seq=4 ttl=60 time=0.316 ms
64 bytes from 1.2.3.2: icmp_seq=4 ttl=60 time=0.316 ms
 
#2. 查询第4列和第7列 - select ip, time from ping;
 
[dwapp@dw_testdb yuechaotian]$ cat ping.txt | awk '{print $4"\t"$7}'
1.2.3.2:        time=0.655
1.22.3.2:       time=0.328
1.2.3.2:        time=0.292
1.22.3.2:       time=0.311
1.2.3.2:        time=0.316
1.2.3.2:        time=0.655
1.2.3.2:        time=0.655
1.22.3.2:       time=0.328
1.2.3.2:        time=0.292
1.22.3.2:       time=0.311
1.2.3.2:        time=0.316
1.22.3.2:       time=0.328
1.2.3.2:        time=0.292
1.22.3.2:       time=0.311
1.2.3.2:        time=0.316
1.22.3.2:       time=0.311
1.22.3.2:       time=0.311
1.2.3.2:        time=0.316
1.2.3.2:        time=0.316
 
 
#3. 查询ip中出现22的 - select ip, time from ping where ip like '%22%';
 
[dwapp@dw_testdb yuechaotian]$ cat ping.txt | awk '{print $4"\t"$7}' | grep 22
1.22.3.2:       time=0.328
1.22.3.2:       time=0.311
1.22.3.2:       time=0.328
1.22.3.2:       time=0.311
1.22.3.2:       time=0.328
1.22.3.2:       time=0.311
1.22.3.2:       time=0.311
1.22.3.2:       time=0.311
 
#4. 查询ip中未出现22的 - select ip, time from ping where ip not like '%22%';
 
[dwapp@dw_testdb yuechaotian]$ cat ping.txt | awk '{print $4"\t"$7}' | grep -v 22
1.2.3.2:        time=0.655
1.2.3.2:        time=0.292
1.2.3.2:        time=0.316
1.2.3.2:        time=0.655
1.2.3.2:        time=0.655
1.2.3.2:        time=0.292
1.2.3.2:        time=0.316
1.2.3.2:        time=0.292
1.2.3.2:        time=0.316
1.2.3.2:        time=0.316
1.2.3.2:        time=0.316
 
#5. 将得到的结果按照time排序 - select ip, time from ping where ip like '%22%' order by time;
 
[dwapp@dw_testdb yuechaotian]$ cat ping.txt | awk '{print $4"\t"$7}' | grep 22 | sort
1.22.3.2:       time=0.311
1.22.3.2:       time=0.311
1.22.3.2:       time=0.311
1.22.3.2:       time=0.311
1.22.3.2:       time=0.311
1.22.3.2:       time=0.328
1.22.3.2:       time=0.328
1.22.3.2:       time=0.328
 
#6. 合并结果中的重复记录 - select distinct ip, time from ping where ip like '%22%' order by time;
 
[dwapp@dw_testdb yuechaotian]$ cat ping.txt | awk '{print $4"\t"$7}' | grep 22 | sort | uniq
1.22.3.2:       time=0.311
1.22.3.2:       time=0.328
 
#7. 统计每个记录的数量 - select count(*), ip, time from ping where ip like '%22%' order by time
 
[dwapp@dw_testdb yuechaotian]$ cat ping.txt | awk '{print $4"\t"$7}' | grep 22 | sort | uniq -c
      5 1.22.3.2:       time=0.311
      3 1.22.3.2:       time=0.328
 
 
参考:
阅读(2169) | 评论(4) | 转发(0) |
0

上一篇:脚本语言初体验 — AWK

下一篇:亦歌

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

chinaunix网友2009-07-20 15:43:14

楼主真厉害

Joyious2009-06-23 12:51:49

恩恩,果然很NB了,我现在顶多也就grep一下,还是不久之前学会的。一到vi里面就手忙脚乱,能推出来就不错了。

chinaunix网友2009-06-17 21:06:20

晕~~~~~不过不知道效率能不能和logparser比

chinaunix网友2009-06-15 13:07:07

最后一个应该是 select count(*), ip, time from ping where ip like '%22%' order by time group by ip,time 吧