Old.txt 包含
apple
orange
banana
Run Code Online (Sandbox Code Playgroud)
并New.txt包含
apple
orange
banana
grape
lemon
Run Code Online (Sandbox Code Playgroud)
我可以访问添加到New.txtusing grep命令的新内容.
grep -Fxvf Old.txt New.txt > difference.txt
Run Code Online (Sandbox Code Playgroud)
现在,difference.txt包含
grape
lemon
Run Code Online (Sandbox Code Playgroud)
在Windows中,我试过了
findstr /rvc:Old.txt New.txt > difference.txt
Run Code Online (Sandbox Code Playgroud)
找到差异,但它也附加了内容Old.txt.如何在Windows中编写等效命令?
您可以使用DOS findstr以下标志: -
/v : Prints only lines that do not contain a match.
/g: file : Gets search strings from the specified file.
Run Code Online (Sandbox Code Playgroud)
该命令将类似于: -
C:\Users\dude\Desktop>findstr /v /g:Old.txt New.txt >difference.txt
Run Code Online (Sandbox Code Playgroud)
现在使用type命令检查文件输出; 相当于cat在Linux,我们看到: -
C:\Users\dude\Desktop>type difference.txt
grape
lemon
Run Code Online (Sandbox Code Playgroud)