Grep for windows

好久不见. 提交于 2019-12-01 17:36:58

问题


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?


回答1:


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



回答2:


Unless you are restricted from installing anything on your PC, considering installing ports of *nix-like tools such as GnuWin32 and continue to use grep.



来源:https://stackoverflow.com/questions/38700487/grep-for-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!