Chinaunix

标题: 谁能帮忙,按照我的要求过滤一些文本? [打印本页]

作者: storysky    时间: 2010-02-10 00:34
标题: 谁能帮忙,按照我的要求过滤一些文本?
文件内容如下
36  00   01   action=ufo
31  00   03   action=ufo
30  00   03   action=ufo
29  00   03   action=ufo
25  00   03   action=bbs
23  00   05   action=bbs
22  00   06   action=bbs
21  00   07   action=bbs
20  00   03   action=ime
20  00   03   action=ime
19  00   03   action=ime
18  00   06   action=ime
.............................

格式就是这样,action=后面有很多类型,我想过滤出每个类型的第一个值。如果按照上面那些例子来说就应该是
36  00   01   action=ufo
25  00   03   action=bbs
20  00   03   action=ime
以此类推。谢谢大家
因为刚才没发悬赏,所以这里补发一下
作者: liying_gg    时间: 2010-02-10 00:34
  1. user@ubuntu:~/script$ cat A
  2. 36  00   01   action=ufo
  3. 31  00   03   action=ufo
  4. 30  00   03   action=ufo
  5. 29  00   03   action=ufo
  6. 25  00   03   action=bbs
  7. 23  00   05   action=bbs
  8. 22  00   06   action=bbs
  9. 21  00   07   action=bbs
  10. 20  00   03   action=ime
  11. 20  00   03   action=ime
  12. 19  00   03   action=ime
  13. 18  00   06   action=ime
  14. user@ubuntu:~/script$ awk '!a[$4]++' A
  15. 36  00   01   action=ufo
  16. 25  00   03   action=bbs
  17. 20  00   03   action=ime
复制代码

作者: chenyx    时间: 2010-02-10 09:19
uniq -f3 -c text.txt
作者: chenyx    时间: 2010-02-10 09:20
本帖最后由 chenyx 于 2010-02-10 09:21 编辑

cat text.txt | uniq -3
假设文件时text.txt
作者: storysky    时间: 2010-02-10 10:25
不对啊 楼上的朋友,
cat action |uniq -4
83 15 16        action=plantInfo 只能显示出一行
uniq -f4 -c action
  86290      83 15        16        action=plantInfo
作者: chenyx    时间: 2010-02-10 10:29
回复 4# storysky


    不是4,是3
作者: storysky    时间: 2010-02-10 11:11
回复  storysky


    不是4,是3
chenyx 发表于 2010-02-10 10:29


3也不行,如果是3的话就会输出很多
作者: liying_gg    时间: 2010-02-10 11:29
回复 7# storysky


    哥的没问题,给哥分吧。
作者: storysky    时间: 2010-02-10 11:45
回复  storysky


    哥的没问题,给哥分吧。
liying_gg 发表于 2010-02-10 11:29


给你分了,谢谢,我给你发了站内信,看下好吗?
还有个方法也能出结果 那就是 sort -u -k4 呵呵




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2