我正在尝试在UNIX上成功完成的新功能,但不知道如何在Windows上执行操作.
所以我保存了一个文本文件,让我们说test1.txt和12小时后比较test2.txt(这是test1.txt与12小时内添加的更改,几乎保证在文件的末尾)到test1.txt然后将文本差异输出到第三个文件diff.txt
1 action
2 action
3 action
4 action
5 action
Run Code Online (Sandbox Code Playgroud)
和test2.txt看起来像
1 action
2 action
3 action
4 action
5 action
6 action
7 action
8 action
Run Code Online (Sandbox Code Playgroud)
然后输出到第三个文件diff.txt看起来像:
6 action
7 action
8 action
Run Code Online (Sandbox Code Playgroud)
只有已添加的文本,没有关于行或比较的信息,只是差异的基本输出.
我完全是新手,环顾四周,似乎我可以写一个批处理文件(.bat),基本上只是作为UNIX脚本.
对不起我的基本问题,但我搜索了这个问题,似乎无法弄明白.
小智 8
最简单,最快速的方法是使用findstr命令进行比较,并将结果返回到脚本中的新文件
findstr /vixg:Z:\misc\test1.txt Z:\misc\misc\test2.txt > Z:\misc\misc\test3.txt
findstr /vixg:<source file> <target file> > outputfile
Run Code Online (Sandbox Code Playgroud)
这里
/v : Prints only lines that do not contain a match.
/i : Specifies that the search is not to be case-sensitive.
/x : Prints lines that match exactly.
/g: file : Gets search strings from the specified file.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24207 次 |
| 最近记录: |