[英]Batch file needed for comparing two files
这是我在Windows批处理文件中的要求,我尝试了以下操作
Example:
f1.txt
sam
varun
ramesh
babu
f2.txt
babu
sam
我需要的输出
varun
ramesh
该程序
@echo on
SETLOCAL EnableDelayedExpansion
for /F "tokens=* delims=." %%a in (f1.txt) do (
call :myInnerLoop "%%a"
)
echo out of inner loop
)
goto :eof
:myInnerLoop
for /F "tokens=* delims=." %%b in (f2.txt) do (
if "%~1"=="%%b" (
echo inside inner loop
goto :next
) else (
echo %%a >> "E:\test\diff.txt"
)
:next
goto :eof
但它不能正常工作对我有帮助。
即使我尝试了diff实用程序,也从http://gnuwin32.sourceforge.net/packages/diffutils.htm没有帮助。
您的代码几乎是正确的,但是您有一些()错误。 试试这个:
@echo off
del d:\test\windows\comp\diff.txt
SETLOCAL EnableDelayedExpansion
for /F "tokens=* delims=." %%a in (f1.txt) do (
echo %%a
call :myInnerLoop "%%a"
)
echo out of inner loop
goto :eof
:myInnerLoop
for /F "tokens=* delims=." %%b in (f2.txt) do (
echo "x: " %~1
echo "y: " %%b
if "%~1"=="%%b" (
echo next
goto :next
)
)
echo "Log " %~1
echo %~1 >> "d:\test\windows\comp\diff.txt"
:next
goto :eof
您在寻找comp
命令吗?
Compares the contents of two files or sets of files.
COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[LINE]]
data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII characters.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
/OFF[LINE] Do not skip files with offline attribute set.
To compare sets of files, use wildcards in data1 and data2 parameters.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.