Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep for windows

Tags:

grep

cmd

findstr

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?

like image 271
Musie Meressa Avatar asked Aug 01 '16 13:08

Musie Meressa


2 Answers

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
like image 194
Inian Avatar answered Sep 20 '22 17:09

Inian


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.

like image 35
Gary_W Avatar answered Sep 18 '22 17:09

Gary_W