博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

剑心通明的资料库

文章均为转载,本人不负因参考它所导致的一切后果,请谨慎参考!如您的文章不愿被转载,请点击此处联系本人!
  jxtm.cublog.cn

关于作者
姓名:剑心通明
职业:高级工程师(专修灵魂^_^)
年龄:20出头30不到
位置:网络上一节点
个性介绍:努力学习每一天!
倾心打造:http://www.bsdlover.cn
http://bbs.bsdlover.cn
BSD爱好者的乐园!
|| << >> ||
我的分类


Display Lines Common in Two Files
Q.I'm trying to use diff command, but it is not working. I'd like to display those lines that are common to file1 and file2? How do I do it?


A.Use comm command; it compare two sorted files line by line. With no options, produce three column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files.
To Display Those Lines That Are Common to File1 and File2Type the command as follows:
$ comm /path/to/file1/ /path/to/file2
$ comm -1 /path/to/file1/ /path/to/file2
$ comm -2 /path/to/file1/ /path/to/file2
$ comm -3 /path/to/file1/ /path/to/file2

Where,
  • -1: suppress lines unique to FILE1
  • -2: suppress lines unique to FILE2
  • -3: suppress lines that appear in both files
    You can also try out perl code (it was posted by someone at comp.unix.shell news group):
    $ perl -ne'print if ($seen{$_} .= @ARGV) =~ /10$/'  file1 file2

     原文地址 http://www.bsdlover.cn/html/56/n-756.html
    发表于: 2008-04-24,修改于: 2008-04-24 09:18,已浏览1638次,有评论1条 推荐 投诉


    网友评论
    网友: buxoman 时间:2008-05-02 11:27:05 IP地址:58.49.29.★
    如果在Emacs中进行用ediff进行比较的话,就有这个特性,可以显示文件中相同的内容和不同的内容。

     发表评论