批生产线的比较 [英] Comparison of the lines with batch
问题描述
我想比较每行before.txt的第一列与after.txt行的第一列(第一行与第一行,第二行与第二行,依此类推).
作为输出,我仅两次获得最后一个值E992A84B8C8A1FEF3B94242403D5D84B
.我的问题是如何比较所有行并获取结果消息?
I want to compare the first column of before.txt with the first column of after.txt line per line ( the first with the first,the second with the second and so on).
As output now I get only the last value E992A84B8C8A1FEF3B94242403D5D84B
two times. My question is how to compare all the lines and get the result message?
FOR /F "tokens=1 delims= " %%G IN (before.txt) DO set variable1=%%G
FOR /F "tokens=1 delims= " %%I IN (after.txt) DO set variable2=%%I
echo !variable1!
echo !variable2!
if /I !variable1!==!variable2! (
echo !variable1! !variable2! md5sum check is ok
)
after.txt
after.txt
94F948D2615318505FD84D722A6F5F4F U:\testbmbf\0012\F96B1522A\MASTER\00000001.tif
4F5022E3290A9A8A4E8905C5CAAFB1A6 U:\testbmbf\0012\F96B1522A\MASTER\00000002.tif
776DF4069AD1914D9C37593E423BC0E4 U:\testbmbf\0012\F96B1522A\MASTER\00000003.tif
95EC963E9C789B3502E1E2C85E505218 U:\testbmbf\0012\F96B1522A\MASTER\00000004.tif
D5DD98F880A7204092EAA9355A4B558B U:\testbmbf\0012\F96B1522A\MASTER\00000005.tif
1A08F9B01904F3EF689B44093343AE2C U:\testbmbf\0012\F96B1522A\MASTER\00000006.tif
437DC62245852A01CCF4F2689F82920E U:\testbmbf\0012\F96B1522A\MASTER\00000007.tif
A4E7C76EC523F1E2799BE8CE049D28FC U:\testbmbf\0012\F96B1522A\MASTER\00000008.tif
177689553B9D9392AD6B72130EE1D22F U:\testbmbf\0012\F96B1522A\MASTER\00000009.tif
EB0F2F741428CF376909AB65BEF6659F U:\testbmbf\0012\F96B1522A\MASTER\00000010.tif
E992A84B8C8A1FEF3B94242403D5D84B U:\testbmbf\0012\F96B1522A\MASTER\00000011.tif
before.txt
before.txt
94F948D2615318505FD84D722A6F5F4F U:\testbmbf\0012\F96B1522A\00000001.tif
4F5022E3290A9A8A4E8905C5CAAFB1A6 U:\testbmbf\0012\F96B1522A\00000002.tif
776DF4069AD1914D9C37593E423BC0E4 U:\testbmbf\0012\F96B1522A\00000003.tif
95EC963E9C789B3502E1E2C85E505218 U:\testbmbf\0012\F96B1522A\00000004.tif
D5DD98F880A7204092EAA9355A4B558B U:\testbmbf\0012\F96B1522A\00000005.tif
1A08F9B01904F3EF689B44093343AE2C U:\testbmbf\0012\F96B1522A\00000006.tif
437DC62245852A01CCF4F2689F82920E U:\testbmbf\0012\F96B1522A\00000007.tif
A4E7C76EC523F1E2799BE8CE049D28FC U:\testbmbf\0012\F96B1522A\00000008.tif
177689553B9D9392AD6B72130EE1D22F U:\testbmbf\0012\F96B1522A\00000009.tif
EB0F2F741428CF376909AB65BEF6659F U:\testbmbf\0012\F96B1522A\00000010.tif
E992A84B8C8A1FEF3B94242403D5D84B U:\testbmbf\0012\F96B1522A\00000011.tif
推荐答案
The usual way to read several files in parallel is described at this answer and consists of read the first file via a for /F
command and the other file(s) via redirected set /P
command(s). For example:
@echo off
setlocal EnableDelayedExpansion
rem First file is read with FOR /F command
rem Second file is read via redirected stdin
< after.txt (for /F %%G in (before.txt) do (
rem Read next line from after.txt
set /P "variable2="
rem Compare first token of both files
for /F %%I in ("!variable2!") do (
if /I %%G==%%I (
echo %%G %%I md5sum check is ok
)
)
))
请注意,默认的for /F
行为是获取第一个以空格分隔的令牌,因此不需要"tokens=1 delims= "
选项...
Note that the default for /F
behavior is get the first token delimited by space, so "tokens=1 delims= "
option is not necessary...
但是,如果文件较小,则可以使用更简单的方法:
However, if the files are small you may use a simpler method:
@echo off
for /F "tokens=1,2 delims=: " %%F in ('findstr /N "^" before.txt') do (
for /F "tokens=1,2 delims=: " %%H in ('findstr /N "^" after.txt') do (
if %%F equ %%H if /I %%G == %%I (
echo %%G %%I md5sum check is ok
)
)
)
在此方法中,findstr /N "^"
命令用于枚举两个文件中的所有行,因此if %%F equ %%H
命令用于同步(选择相同)行在两个文件中.这种方法效率不高,因此如果文件不小的话会花费更长的时间...
In this method a findstr /N "^"
command is used to enumerate all lines in both files, so if %%F equ %%H
command is used to synchronize (select the same) lines in both files. This method is not efficient, so it will take longer if the files are not small...
这篇关于批生产线的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!