用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-[email protected] 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‘
时间: 2024-10-10 07:22:43