Grep for windows

Old.txt contains

apple
orange
banana

And New.txtcontains

apple
orange
banana
grape
lemon

I can access the new content that has been added to New.txtwith the command grep.

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

Now difference.txtcontains

grape
lemon

On Windows I tried

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

to find the difference, but it also adds content Old.txt. How to write an equivalent command in Windows?

+4
source share
2 answers

You can use DOS findstrwith the following flags: -

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

The command will look something like this: -

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

Now check the output of the file with the command type; equivalent catto Linux, we see: -

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

- , * nix, GnuWin32 grep.

+1

Source: https://habr.com/ru/post/1649794/


All Articles