zoukankan      html  css  js  c++  java
  • 找出两个文本文件的不同的行

    用shell找出两个文本文件的不同的行
    
    亲自实验过的方法如下:
    第一种:comm命令法
    命令如下:comm -3 file1 file2
    有一个问题就是,如果两个文件排序不一样的话,会出问题
    
    第二种:grep命令法
    命令如下:grep -vwf file1 file2
    统计file1中没有,file2中有的行
    
    具体使用环境以后再补充,今天先记录到这里。
    参考文档:
    1、找出两个文件内容的相同与不同:http://blog.csdn.net/shuckstark/article/details/7872176
    2、comm命令:http://michaels.blogbus.com/logs/44427299.html
    3、linux grep用法:http://blog.csdn.net/greytree/article/details/428532
    4、linux grep命令:ttp://www.cnblogs.com/end/archive/2012/02/21/2360965.html
    找出两个文件不同的数据    
    #!/bin/sh 
    function _diffab(){
    x=0
    for i in `cat $1`;do
            for j in `cat $2`;do
                    if [ $i == $j ];then
                            x=1
                            break;
                    fi
            done
                    if [ $x -ne 1 ];then
                            echo $i
                    fi
            x=0
    done
    }
     
    if [ "$1" == "" ] || [ "$2" == "" ];then
    echo "use like this: $0 filea fileb"
    else
    {
    _diffab $1 $2
    _diffab $2 $1
    }
    fi
    $ comm --help
    Usage: comm [OPTION]... FILE1 FILE2
    Compare sorted files FILE1 and FILE2 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.
    
      -1              suppress column 1 (lines unique to FILE1)
      -2              suppress column 2 (lines unique to FILE2)
      -3              suppress column 3 (lines that appear in both files)
    
      --check-order     check that the input is correctly sorted, even
                          if all input lines are pairable
      --nocheck-order   do not check that the input is correctly sorted
      --output-delimiter=STR  separate columns with STR
          --help     display this help and exit
          --version  output version information and exit
    
    Note, comparisons honor the rules specified by `LC_COLLATE'.
    
    Examples:
      comm -12 file1 file2  Print only lines present in both file1 and file2.
      comm -3  file1 file2  Print lines in file1 not in file2, and vice versa.
    
    Report comm bugs to bug-coreutils@gnu.org
    GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
    General help using GNU software: <http://www.gnu.org/gethelp/>
    For complete documentation, run: info coreutils 'comm invocation'
  • 相关阅读:
    Visual Studio 2010使用Visual Assist X的方法
    SQL Server 2000 评估版 升级到 SQL Server 2000 零售版
    双网卡多网络单主机同时访问
    开发即过程!立此纪念一个IT新名词的诞生
    delphi dxBarManager1 目录遍历 转为RzCheckTree2树
    5320 软件集合
    delphi tree 从一个表复制到另一个表
    DELPHI 排课系统课表
    长沙金思维 出现在GOOGLE的 金思维 相关搜索里啦!!
    如何在DBGrid的每一行前加一个单选框?
  • 原文地址:https://www.cnblogs.com/timssd/p/4950762.html
Copyright © 2011-2022 走看看