我有两个文件file1.txt和file2.txt
File1.txt:
abc
def
xyz
File2.txt
abc
比较file1.txt和file2.txt并创建两个文件,一个有差异,另一个文件显示相似之处。 任何人都可以帮我解决这样的批处理程序。
答案 0 :(得分:2)
GNU awk的Windows代码:
awk "NR==FNR {a[$0]=$0; next}; {b[$0]=$0};a[$0]==$0;END {for (i in a) {if (b[i]==0) {print a[i] >\"diff.txt\"}};for (i in b) {if (a[i]==0) {print b[i]>>\"diff.txt\"}}}" file1 file2
输出示例:
>type file1,file2 file1 AAAAA 44444 BBBBB 55555 CCCCC 66666 DDDDD file2 AAAAA 11111 BBBBB 22222 CCCCC 33333 DDDDD >awk "NR==FNR {a[$0]=$0; next}; {b[$0]=$0};a[$0]==$0;END {for (i in a) {if (b[i]==0) {print a[i] >\"diff.txt\"}};for (i in b) {if (a[i]==0) {print b[i]>>\"diff.txt\"}}}" file1 file2>match.txt >type match.txt,diff.txt match.txt AAAAA BBBBB CCCCC DDDDD diff.txt 44444 55555 66666 11111 22222 33333 >
纯粹batch:
findstr /l /g:file1 file2>match.txt
findstr /lv /g:file1 file2>diff.txt
findstr /lv /g:file2 file1>>diff.txt