适用于 Windows 的 Grep [英] Grep for windows

查看:26
本文介绍了适用于 Windows 的 Grep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Old.txt 包含

apple
orange
banana

并且New.txt包含

apple
orange
banana
grape
lemon

我可以使用 grep 命令访问添加到 New.txt 的新内容.

I can access new contents which are added to New.txt using grep command.

grep -Fxvf Old.txt New.txt > difference.txt 

现在,difference.txt 包含

grape
lemon

在Windows中,我试过

In Windows, I have tried

findstr /rvc:Old.txt New.txt > difference.txt 

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

to find the difference but it append contents of Old.txt too. How can I write equivalent command in Windows?

推荐答案

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

You can use DOS findstr with the following flags:-

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

命令类似于:-

C:UsersdudeDesktop>findstr /v /g:Old.txt New.txt >difference.txt

现在使用type命令检查文件输出;相当于Linux中的cat,我们看到:-

Now checking the file output using the type command; equivalent to cat in Linux, we see :-

C:UsersdudeDesktop>type difference.txt
grape
lemon

这篇关于适用于 Windows 的 Grep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆