China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 04:57
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Problem with Comparing Two Files View 3,289 Replies 52
Original Poster Posted 2008-07-09 11:28 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Suppose I have the following 2 files

1.txt

HPQ	CD4E1902
Pavilion 06D652A4
Lenovo 5237B729
LEGEND 7B06BD13
IBM D7A77612
TOSHIBA A16F9D62
FUJITSU 10045CFA
FUJITSUS D2D64C41
HEDY 162C7931
Founder 3A0C0121


2.txt

G:\I386\OEMBIOS.CA_
G:\WXPOEM\1\OEMBIOS.CAT
G:\WXPOEM\2\OEMBIOS.CAT
G:\WXPOEM\3\OEMBIOS.CA_
G:\WXPOEM\4\OEMBIOS.CAT
G:\WXPOEM\5\OEMBIOS.CAT
G:\WXPOEM\6\OEMBIOS.CAT
G:\WXPOEM\7\OEMBIOS.CAT
G:\WXPOEM\8\OEMBIOS.CAT
F:\cpl\thif\OEMBIOS.CA_
F:\新建文件夹\Acer\OEMBIOS.CA_
F:\新建文件夹\xxx\OEMBIOS.CA_
F:\新建文件夹\Lenovo\oembios.ca_
F:\新建文件夹\xx\OEMBIOS.CA_


Now I get a variable value, for example HEDY, which is the first value in the line in file 1.txt.

I perform CRC32 checksum on the files in the paths in 2.txt (if it is a compressed file, first EXPAND), run CRC32.EXE, assume that the CRC output result is the 2nd token in the first line, then compare with the 2nd line value in file 1.txt, IF FIND, then assign the corresponding path to a variable.

How to write code efficiently, concisely and understandably without using third-party programs? Thanks.

To supplement, the CRC value check is only run once, but the result of the check may be called multiple times, so generating the following result file is more appropriate.

LEGEND	7B06BD13 F:\新建文件夹\xxx\OEMBIOS.CA_
HEDY 162C7931 G:\WXPOEM\5\OEMBIOS.CAT


[ Last edited by quya on 2008-7-9 at 12:01 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 2 Posted 2008-07-09 12:40 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
Is this something that checks if it's a virus copy after MD5 verification?
Floor 3 Posted 2008-07-09 13:19 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Didn't use crc32, roughly wrote:

@echo off
for /f "delims=" %%i in (2.txt) do crc32 %%i>>crc.txt
for /f "tokens=2" %%a in (1.txt) do (
for /f "tokens=1,3" %%i in ('findstr "%%a" crc.txt') do if "%%i" neq "" echo set %%i=%%j
)
pause>nul


[ Last edited by zw19750516 on 2008-7-9 at 01:27 PM ]
批处理之家新域名:www.bathome.net
Floor 4 Posted 2008-07-09 13:35 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
This problem I think is relatively complicated.

1. First, we need to extract the unzipped files to a temporary directory for verification. Because the original directory may be read-only, in this case, we need to save the original unzipped path value.

2. Just like I supplemented at the end of my first-floor post, I need to put the results into a file for multiple calls. As for the CRC running command format and the result, it's secondary. As long as we know it will definitely output a result. Just like in the 3rd floor, we just need to know that there is a CRC.TXT file, and there are various values in it.

3. The difficult part is to output the result after comparison, that is, to output the values of 1.txt, 2.txt, and crc.txt through a feature value again.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 5 Posted 2008-07-09 13:41 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
It would be best to give some samples of the part of the crc.txt file...
致精致简!
Floor 6 Posted 2008-07-09 13:53 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Originally posted by 26933062 at 2008-7-9 01:41 PM:
It would be best to give some samples of the part of the crc.txt file...


I can't remember the samples, but this is a common issue.


F:\New Folder\xxx\OEMBIOS.CA_ Assume here expand F:\New Folder\xxx\OEMBIOS.CA_ %temp%\OEMBIOS.CAT

crc32 %temp%\OEMBIOS.CAT

Running result ??? 7B06BD13 ???? (just an example, may not be the actual one, ??? represents anything)

G:\WXPOEM\5\OEMBIOS.CAT

crc32 G:\WXPOEM\5\OEMBIOS.CAT

Running result ??? 162C7931 ????


To be universal, assume I first try to get the following a CRC file (actually this file may not be needed, as long as the final result, but let's take it step by step)

CRC.TXT

G:\I386\OEMBIOS.CA_	???
G:\WXPOEM\1\OEMBIOS.CAT ??? (and so on)
G:\WXPOEM\2\OEMBIOS.CAT
G:\WXPOEM\3\OEMBIOS.CA_
G:\WXPOEM\4\OEMBIOS.CAT
G:\WXPOEM\5\OEMBIOS.CAT 162C7931
G:\WXPOEM\6\OEMBIOS.CAT
G:\WXPOEM\7\OEMBIOS.CAT
G:\WXPOEM\8\OEMBIOS.CAT
F:\cpl\thif\OEMBIOS.CA_
F:\New Folder\Acer\OEMBIOS.CA_
F:\New Folder\xxx\OEMBIOS.CA_ 7B06BD13
F:\New Folder\Lenovo\oembios.ca_
F:\New Folder\xx\OEMBIOS.CA_


Finally, what I want to get is something like the following result

LEGEND        7B06BD13 F:\New Folder\xxx\OEMBIOS.CA_
HEDY 162C7931 G:\WXPOEM\5\OEMBIOS.CAT


Describing this problem in words is like this.

My computer has a VOL version of XP installed, and now I want to change it to an OEM version. My motherboard has OEM characteristics, and I have a large number of OEMBIOS files available to replace the files needed by the system. In order to find the accurate OEMBIOS files, I put them in specific folders for the program to automatically find.

Then I thought whether it could be more accurate. For example, if I put the wrong file in the folder, if I just put it randomly in a folder? Can I compile a batch file to quickly and accurately find it?

The problem is like this. And I found that this problem can also be applied in other places, and there should be many similar application examples of finding.

[ Last edited by quya on 2008-7-9 at 02:19 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 7 Posted 2008-07-09 14:34 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
After talking a lot, I didn't understand your intention from floor 1 to floor 6.
I guess I wrote a code. Let's see if it's correct...
Note: The situation where the file name and path in crc.txt contain spaces is not considered, and the situation where the first column of the content in 1.txt contains spaces is not considered.
And under the premise that there are no duplicates in the??? part of crc.txt.
:

@echo off&setlocal enabledelayedexpansion
for /f "tokens=1* delims= " %%a in (1.txt) do set %%b=%%a
for /f "tokens=1,2 delims= " %%a in (crc.txt) do (
if defined %%b echo !%%b! %%b %%a
)
pause


[ Last edited by 26933062 on 2008-7-9 at 02:42 PM ]
致精致简!
Floor 8 Posted 2008-07-09 15:24 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
If I run (for simplicity, temporarily not considering the issue of extracting OEMBIOS.CA_ to the temporary directory OEMBIOS.CAT first)

for /f %i in (2.txt) do crc32 %i >crc.txt


Get a crc.txt, this is also simulated, actually it may not be that simple, but I will handle it.

3261089
9308173
2513351
4769779
2389039
162C7931
3468033
3351192
3627383
8631970
3820293
7B06BD13
4832250
8878816


First question:

How can I combine 2.txt and CRC.txt into the following file temp.txt (if the second question can be directly solved, this file can be omitted)

temp.txt (among the table, only 2 values are real, others are virtual by me)

Path CRC value

G:\I386\OEMBIOS.CA_ 3261089
G:\WXPOEM\1\OEMBIOS.CAT 9308173
G:\WXPOEM\2\OEMBIOS.CAT 2513351
G:\WXPOEM\3\OEMBIOS.CA_ 4769779
G:\WXPOEM\4\OEMBIOS.CAT 2389039
G:\WXPOEM\5\OEMBIOS.CAT 162C7931
G:\WXPOEM\6\OEMBIOS.CAT 3468033
G:\WXPOEM\7\OEMBIOS.CAT 3351192
G:\WXPOEM\8\OEMBIOS.CAT 3627383
F:\cpl\thif\OEMBIOS.CA_ 8631970
F:\New Folder\Acer\OEMBIOS.CA_ 3820293
F:\New Folder\xxx\OEMBIOS.CA_ 7B06BD13
F:\New Folder\Lenovo\oembios.ca_ 4832250
F:\New Folder\xx\OEMBIOS.CA_ 8878816


Second question

How to get the following file according to temp.txt and 1.txt through a common CRC value

LEGEND        7B06BD13 F:\New Folder\xxx\OEMBIOS.CA_
HEDY 162C7931 G:\WXPOEM\5\OEMBIOS.CAT

Third question

Do not simplify the steps, solve my actual problem.

Actually, CRC is just a transition, I just find the directory of the specific file I need through the CRC value, and this specific file may be in a CAB compression on a read-only disk, I have to decompress it first and then detect. If the complicated steps I mentioned above are not needed, then it is the best.

The final result I really need is similar to the following style:

There are no restrictions on the following 2 values, there may be only one value, or no result if not found.

LEGEND         F:\New Folder\xxx\OEMBIOS.CA_
HEDY G:\WXPOEM\5\OEMBIOS.CAT


[ Last edited by quya on 2008-7-9 at 04:10 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 9 Posted 2008-07-09 16:16 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
The key point is that we don't know what the result of running crc32.exe is.
You first run the following code and post the result to see.
:

@echo off
for /f "delims=" %%a in (2.txt) do (
for /f "delims=" %%i in ('crc32 %%a') do echo %%i
)
pause
致精致简!
Floor 10 Posted 2008-07-09 16:19 ·  中国 江苏 常州 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
```
@echo off
for /f "delims=" %%j in (2.txt) do (
for /f "delims=" %%j in ('crc32 "%%i"') do (
for /f "delims=" %%k in ('findstr /ic:"%%j" "1.txt"') do (
if not "%%k"=="" echo %%k %%i
)
)
)
pause
```
简单!简单!再简单!
Floor 11 Posted 2008-07-09 16:45 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
To: Floor 9

I don't have CRC software right now. I won't know until晚上. You can assume the simplest one, which is CRC32.EXE Filename outputs the CRC value. Because no matter the actual CRC running result, I know how to handle it. This isn't the key.

To: Floor 10

I'll verify your code after get off work. Three nested FORs make me dizzy. Maybe your code will run correctly when the OEMBIOS is fully decompressed, but considering the compressed OEMBIOS.CA_, the situation will be complicated. Can you generate the intermediate file first so that I can parse it to solve the actual problem?

Thank you everyone.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 12 Posted 2008-07-09 17:10 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
The idea on floor 10 is basically accurate. I modified the second FOR loop according to the meaning of floor 10 and verified it.

@echo off
for /f "delims=" %%j in (2.txt) do (
for /f "delims=" %%j in (crc.txt) do (
for /f "delims=" %%k in ('findstr /ic:"%%j" "1.txt"') do (
if not "%%k"=="" echo %%k %%i
)
)
)
pause


The running result is: (Can it be further improved and made more efficient? Thanks!) %i is not displayed correctly as the path! My main purpose is to obtain the path.

HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
HEDY 162C7931 %i
LEGEND 7B06BD13 %i
Press any key to continue...


As for the acquisition of the CRC.TXT file, my preliminary idea is the following code, which has not been run and verified, and may need to use delayed variables and so on.

for /f %%i in (2.txt) do (if %~xi==cat crc32 %%i>>crc.txt else (expand %%i %temp%\oembios.cat &crc32 %temp%\oembios.cat>>crc.txt))


[ Last edited by quya on 2008-7-9 at 05:13 PM ]
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 13 Posted 2008-07-09 17:23 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
21-year member
UID 44210
Status Offline
The 10th floor had a wrong character, so there was a little error when running on the 12th floor
@echo off
for /f "delims=" %%i in (2.txt) do (
for /f "delims=" %%j in ('crc32 "%%i"') do (
for /f "delims=" %%k in ('findstr /ic:"%%j" "1.txt"') do (
if not "%%k"=="" echo %%k %%i
)
)
)
pause
Floor 14 Posted 2008-07-09 17:28 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Assume your WinRAR storage path is c:\progra~1\winrar\,as follows:

@echo off&setlocal enabledelayedexpansion
for /f %%a in (2.txt) do (
if "%%~xa" equ ".rar" (
call c:\progra~1\winrar\rar x %%a %%~dpa\
for /f "delim=" %%i in ('crc32 "%%~dpna.CA*"') do set str=%%i
) else (
for /f "delims=" %%i in ('crc32 "%%a"') do set str=%%i
)
echo !str! %%a>>crc.txt
)
rem Assume crc.exe *.* is in the form listed by the original poster
for /f "tokens=1,2" %%a in (crc.txt) do (
for /f "delims=" %%i in ('findstr "%%a" 1.txt') do echo %%i %%b
)


[ Last edited by zw19750516 on 2008-7-9 at 06:04 PM ]
批处理之家新域名:www.bathome.net
Floor 15 Posted 2008-07-09 17:31 ·  中国 江苏 苏州 常熟市 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
Originally posted by zh159 at 2008-7-9 05:23 PM:
There is a character error in floor 10, so there is a slight error when running in floor 12


No, the path name is completely useless. Even if J is changed to I, the result is wrong.

Thank you to floor 10 and other friends who helped. Can you take another look? I really can't figure it out.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Forum Jump: