|
Answer» Hi Friends,
Is it possible to compare 2 text file USING DOS command? Please advise. The clear data is mentioned below for your reference.
content on File1: 1.zip 2.zip 3.zip 4.zip
content on File2: 1.zip 2.zip 4.zip
The output file should display the 3.zip which is not in file2 but on file1. Please help on this. Thanks.If 3 zip isn't on file 2 it won't show in the content output...no matter what you do...Hi Patio,
Thanks much foir quick reply. Is there is any possiblity to print the line which is not in file2 but which is available on file1? Please adviseCode: [Select]@echo off setlocal enabledelayedexpansion
echo 1.zip > File1 echo 2.zip >> File1 echo 3.zip >> File1 echo 4.zip >> File1 echo 5.zip >> File1 echo 6.zip >> File1 echo 7.zip >> File1 echo 8.zip >> File1 echo 9.zip >> File1 echo 10.zip >> File1
echo 1.zip > File2 echo 2.zip >> File2 REM echo 3.zip >> File2 echo 4.zip >> File2 echo 5.zip >> File2 REM echo 6.zip >> File2 echo 7.zip >> File2 echo 8.zip >> File2 echo 9.zip >> File2 echo 10.zip >> File2 echo 99.zip >> File2
for /f "delims=" %%A in (File1) do ( set found=1 For /F "delims=" %%B in (File2) do if "%%A"=="%%B" set /a found+=1 if not !found! equ 2 echo %%A is present in File1 but not in File2 )
for /f "delims=" %%A in (File2) do ( set found=1 For /F "delims=" %%B in (File1) do if "%%A"=="%%B" set /a found+=1 if not !found! equ 2 echo %%A is present in File2 but not in File1 )
Code: [Select]3.zip is present in File1 but not in File2 6.zip is present in File1 but not in File2 99.zip is present in File2 but not in File1Fixed a possible bug if a line is present more than once in one of the files
Code: [Select]@echo off setlocal enabledelayedexpansion
echo 1.zip > File1 echo 2.zip >> File1 echo 3.zip >> File1 echo 4.zip >> File1 echo 5.zip >> File1 echo 6.zip >> File1 echo 7.zip >> File1 echo 8.zip >> File1 echo 9.zip >> File1 echo 10.zip >> File1
echo 1.zip > File2 echo 2.zip >> File2 REM echo 3.zip >> File2 echo 4.zip >> File2 echo 5.zip >> File2 REM echo 6.zip >> File2 echo 7.zip >> File2 echo 8.zip >> File2 echo 9.zip >> File2 echo 10.zip >> File2 echo 99.zip >> File2
for /f "delims=" %%A in (File1) do ( set found=1 For /F "delims=" %%B in (File2) do if "%%A"=="%%B" set /a found+=1 if !found! equ 1 echo %%A is present in File1 but not in File2 )
for /f "delims=" %%A in (File2) do ( set found=1 For /F "delims=" %%B in (File1) do if "%%A"=="%%B" set /a found+=1 if !found! equ 1 echo %%A is present in File2 but not in File1 )
Code: [Select]3.zip is present in File1 but not in File2 6.zip is present in File1 but not in File2 99.zip is present in File2 but not in File1of course, a batch script is just about the slowest way to do this sort of THING, especially if the file sizes are larger than just a few lines. I tried the script above on two 10,000 line files and the time was 15 minutes for each compare. With VBScript it was down to 2 minutes. fc file1 file2
OR output to file
fc file1 file2 > diffs.txt
Why doesn't this work for you?
Quote from: sandy1000 on June 23, 2011, 10:19:51 AM fc file1 file2 The original poster desired to find which strings were present in the first file but not in the second. The FC command merely does a simple comparison. If we assume that the second file is just a copy of the first but with one or more lines deleted, then FC will flag every line after the missing one as a "difference", whether or not it is missing from the first file. Possibly by a diligent EXAMINATION ofthe output it might be possible to discover the required information, but ti WOULD not be very convenient.
|