Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
Linux 比较两个脚本文件并查找不匹配的数据_Linux_Bash_Shell_Awk - Fatal编程技术网

Linux 比较两个脚本文件并查找不匹配的数据

Linux 比较两个脚本文件并查找不匹配的数据,linux,bash,shell,awk,Linux,Bash,Shell,Awk,我有两个.txt文件,其中数据以 1.txt 及 2.txt ` 我需要找到1.txt中的文件,但不是2.txt中的文件 我试着用 diff -a --suppress-common-lines -y 1.txt 2.txt > finaloutput 但它不起作用而不是diff您可以在此处使用comm: comm -23 <(sort 1.txt) <(sort 2.txt) ASF001-AS-ST105U33 ASF001-AS-ST107U20 一个相对简单的bas

我有两个.txt文件,其中数据以

1.txt

2.txt

` 我需要找到1.txt中的文件,但不是2.txt中的文件

我试着用

diff -a --suppress-common-lines -y 1.txt 2.txt > finaloutput

但它不起作用

而不是diff您可以在此处使用
comm

comm -23 <(sort 1.txt) <(sort 2.txt)
ASF001-AS-ST105U33
ASF001-AS-ST107U20

一个相对简单的bash脚本可以满足您的需要:

#!/bin/bash

while read line || test -n "$line"; do 
    grep -q $line "$2" || echo "$line"
done < "$1"

exit 0
comm -23 <(sort 1.txt) <(sort 2.txt)
ASF001-AS-ST105U33
ASF001-AS-ST107U20
awk 'FNR==NR {a[$1];next} $1 in a{delete a[$1]} END {for (i in a) print i}' 1.txt 2.txt
ASF001-AS-ST107U20
ASF001-AS-ST105U33
#!/bin/bash

while read line || test -n "$line"; do 
    grep -q $line "$2" || echo "$line"
done < "$1"

exit 0
$ ./uniquef12.sh dat/1.txt dat/2.txt
ASF001-AS-ST105U33
ASF001-AS-ST107U20