compare text files and ..
Moderator: DosItHelp
compare text files and ..
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
thanks a lot
Re: compare text files and ..
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
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 ..
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 ..
Here:
Code: Select all
FindStr/vxg:file1.txt file2.txt>namefile.txt
Re: compare text files and ..
@foxidrive, regardless of any benefits of:
- /x string
- ^string$
- /b /e string
- \<string\>
Code: Select all
FindStr [/Option(s)] String(s) FileName
Re: compare text files and ..
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 ..
thanks to everyone , I try , good job Compo , Ben Mar , Foxi , very helpful for me