Page 1 of 1

compare text files and ..

Posted: 11 Jun 2015 23:57
by code
Good morning, I would need your help , I have to compare two files .txt (file1.txt file2.txt) both contain a list of ip but file 2.txt are the list ip updated and file1.txt is old list ip ...I want get a result in another file txt as a result ip missing in old file 1.txt , comand fc not work wel , because it gives me the difference understood as tabulation , because give me the difference in paragraph , I want to get from comparison from old file1.txt updated file2.txt List of IP that are not present in the old file 1.txt
thanks a lot

Re: compare text files and ..

Posted: 12 Jun 2015 03:08
by foxidrive
Test this:

Code: Select all

type file2.txt|findstr /v /l /g:file1.txt

Re: compare text files and ..

Posted: 12 Jun 2015 12:23
by code
I thank you very much for the help you give , seems work, I only added that in order to have the result in a file txt

type file2.txt|findstr /v /l /g:file1.txt >namefile.txt and the path of the file

thanks again for all

Re: compare text files and ..

Posted: 12 Jun 2015 18:42
by Ben Mar
foxidrive wrote:Test this:

Code: Select all

type file2.txt|findstr /v /l /g:file1.txt

Let's assume the content of file1.txt is like this:

Code: Select all

127.0.0.1
127.0.0.3
127.0.0.5
127.0.0.7
127.0.0.9
127.0.0.11
127.0.0.13
127.0.0.15


Let's assume the content of file2.txt is like this:

Code: Select all

127.0.0.1
127.0.0.2
127.0.0.3
127.0.0.4
127.0.0.5
127.0.0.6
127.0.0.7
127.0.0.8
127.0.0.9
127.0.0.10
127.0.0.11
127.0.0.12
127.0.0.13
127.0.0.14
127.0.0.15
127.0.0.16


The above code just give this result:

Code: Select all

127.0.0.2
127.0.0.4
127.0.0.6
127.0.0.8


I come up with the normal comparison method like this:

Code: Select all

@echo off
setlocal enabledelayedexpansion
(
   for /f %%A in (file2.txt) do (
      set found=0
      for /f %%B in (file1.txt) do (
          if "%%A"=="%%B" set found=1
      )
      if !found! equ 0 echo %%A
   )
)>namefile.txt


and it will give the expected result:

Code: Select all

127.0.0.2
127.0.0.4
127.0.0.6
127.0.0.8
127.0.0.10
127.0.0.12
127.0.0.14
127.0.0.16

Re: compare text files and ..

Posted: 13 Jun 2015 00:28
by Compo
Here:

Code: Select all

FindStr/vxg:file1.txt file2.txt>namefile.txt

Re: compare text files and ..

Posted: 13 Jun 2015 03:33
by foxidrive
This should also solve it:

Code: Select all

type file2.txt|findstr /v /l /b /e /g:file1.txt

Re: compare text files and ..

Posted: 13 Jun 2015 06:55
by Compo
@foxidrive, regardless of any benefits of:
  • /x string
  • ^string$
  • /b /e string
  • \<string\>
What is, if any, the benefit of using Type and piping it into FindStr over the documented

Code: Select all

FindStr [/Option(s)] String(s) FileName

Re: compare text files and ..

Posted: 13 Jun 2015 08:33
by foxidrive
Compo wrote:What is, if any, the benefit of using Type and piping it into FindStr


None! Did I say that there was? ;)

It's more inefficient as you probably well know - I didn't bother changing it to your better style because I'm still a bit crook and I just copy and pasted.

I have trouble concentrating and just flick through all the recent discoveries and code, too much for a bear with little brain.

Re: compare text files and ..

Posted: 15 Jun 2015 15:22
by code
thanks to everyone , I try , good job Compo , Ben Mar , Foxi , very helpful for me