Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 两个unix文件中的值不匹配_Shell - Fatal编程技术网

Shell 两个unix文件中的值不匹配

Shell 两个unix文件中的值不匹配,shell,Shell,我有两个仅包含数值的unix文件,例如: 文件1: 12345 23456 234578 文件2: 2387 12345 23456 767888 我需要从两个文件中分离不常见的值,例如:2345782387767688。并使用shell脚本直接导入一个单独的文件。请告知。comm可用于查找其中一个文件特有的行 sort file1.txt > file1.srt sort file2.txt > file2.srt comm -2 -3 file1.srt file2.srt &g

我有两个仅包含数值的unix文件,例如:

文件1:
12345
23456
234578

文件2:
2387
12345
23456
767888


我需要从两个文件中分离不常见的值,例如:2345782387767688。并使用shell脚本直接导入一个单独的文件。请告知。

comm
可用于查找其中一个文件特有的行

sort file1.txt > file1.srt
sort file2.txt > file2.srt
comm -2 -3 file1.srt file2.srt > only1.txt
comm -1 -3 file1.srt file2.srt > only2.txt

排序fileA fileB | uniq-u>fileC

添加到上面:sort-u only 1.txt only 2.txt以获取所有唯一项:此外,我们还可以组合两个文件:cat only1.txt only2.txt>uniq:-)