cmd - 适用于 Windows 的 Grep

标签 cmd grep findstr

Old.txt包含

apple
orange
banana

New.txt包含
apple
orange
banana
grape
lemon

我可以访问添加到 New.txt 的新内容使用 grep命令。
grep -Fxvf Old.txt New.txt > difference.txt 

现在,difference.txt包含
grape
lemon

在 Windows 中,我尝试过
findstr /rvc:Old.txt New.txt > difference.txt 

找到差异,但它附加了 Old.txt 的内容也。如何在 Windows 中编写等效命令?

最佳答案

您可以使用 DOS findstr 带有以下标志:-

/v   : Prints only lines that do not contain a match.
/g: file   : Gets search strings from the specified file.

该命令将类似于:-
C:\Users\dude\Desktop>findstr /v /g:Old.txt New.txt >difference.txt

现在使用 type 检查文件输出命令;相当于 catLinux , 我们看 :-
C:\Users\dude\Desktop>type difference.txt
grape
lemon

关于cmd - 适用于 Windows 的 Grep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38700487/

相关文章:

powershell - 替换两个特定字符串之间的行 - 在 cmd 中等效于 sed

batch-file - 批量 if 语句问题

java - 通过定义正则表达式过滤日志文件

windows - findstr 命令查找短语而不是单个单词

regex - 如何使用 findstr 提取子字符串

windows - unicode 不从 bat 显示

windows - 将输出重定向到 VAR 指定的文件名

shell 脚本中 'hr min sec' 时间格式的正则表达式?

linux - 获取时间跨度内的日志文件行

batch-file - 使用批处理文件删除重复的文本行