grep for windows [英] Grep for windows

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

问题描述

code> Old.txt 包含

  apple 
orange
banana

New.txt 包含

 苹果
橙色
香蕉
葡萄
柠檬

我可以访问添加到 New.txt 使用 grep 命令。

  grep -Fxvf Old.txt新建。 txt> difference.txt 

现在, difference.txt 包含

 葡萄
柠檬

在Windows中,我试过了

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

查找差异,但它追加 Old.txt的内容也是。如何在Windows中编写相应的命令?

解决方案

您可以使用 DOS findstr 使用以下标记: -

  / v:仅打印不包含匹配的行。 
/ g:file:从指定文件中获取搜索字符串。

该命令可能类似于: - $ /

  C:\Users\dude\Desktop> findstr / v /g:Old.txt New.txt> difference.txt 

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

  C:\Users\dude\Desktop>类型difference.txt 
葡萄
柠檬


Old.txt contains

apple
orange
banana

And New.txt contains

apple
orange
banana
grape
lemon

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

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

Now, difference.txt contains

grape
lemon

In Windows, I have tried

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

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

解决方案

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.

The command would be something like:-

C:\Users\dude\Desktop>findstr /v /g:Old.txt New.txt >difference.txt

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

C:\Users\dude\Desktop>type difference.txt
grape
lemon

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

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