用于比较没有 headers 重复文本文件的批处理文件
Batch file to compare text files with no headers for duplicates
我需要创建一个批处理文件来执行以下操作:我有 2 个没有 headers 的文本文件,我需要相互比较某一列中的重复项。
文件 1 看起来像:
34551897 455684 2170865488
34668571 455674 2165586244
34156474 456178 2156189465
34156184 428516 2153185687
文件 2 看起来像:
3415647 458566 2183154897
3515647 168594 2156984161
3513157 412348 2156748416
3581354 154613 2156789131
我需要比较文件 1 和文件 2 的第二列是否重复,如果有重复,return 为零。否则,return 一个 1。
文本文件位于同一台机器上,但位于不同的文件夹中。
如有任何帮助,我们将不胜感激。提前致谢。
如果匹配字符串的位置无关紧要,这可能会有所帮助:
@echo off
setlocal enabledelayedexpansion
set count=0
for /f "usebackq tokens=2 delims=TAB " %%i in ("C:\TEST\test columns 1.txt") do (
echo %%i
)>>C:\TEST\temp.txt
for /f "usebackq tokens=2 delims=TAB " %%i in ("C:\TEST\test columns 2.txt") do (
findstr /c:"%%i" "C:\TEST\temp.txt"
if !errorlevel!==0 set /a count+=1
)
echo !count! match(es)
pause
del /q "C:\TEST\temp.txt"
您需要将路径替换为与您相关的路径。此外,您可以通过 嵌套 for
条件来更有效地做到这一点:
@echo off
setlocal enabledelayedexpansion
set count=0
for /f "usebackq tokens=2 delims=TAB " %%i in ("C:\TEST\test columns 1.txt") do (
for /f "usebackq tokens=2 delims=TAB " %%j in ("C:\TEST\test columns 2.txt") do (
if %%i==%%j set /a count+=1
)
)
echo !count! match(es)
pause
我需要创建一个批处理文件来执行以下操作:我有 2 个没有 headers 的文本文件,我需要相互比较某一列中的重复项。
文件 1 看起来像:
34551897 455684 2170865488
34668571 455674 2165586244
34156474 456178 2156189465
34156184 428516 2153185687
文件 2 看起来像:
3415647 458566 2183154897
3515647 168594 2156984161
3513157 412348 2156748416
3581354 154613 2156789131
我需要比较文件 1 和文件 2 的第二列是否重复,如果有重复,return 为零。否则,return 一个 1。
文本文件位于同一台机器上,但位于不同的文件夹中。
如有任何帮助,我们将不胜感激。提前致谢。
如果匹配字符串的位置无关紧要,这可能会有所帮助:
@echo off
setlocal enabledelayedexpansion
set count=0
for /f "usebackq tokens=2 delims=TAB " %%i in ("C:\TEST\test columns 1.txt") do (
echo %%i
)>>C:\TEST\temp.txt
for /f "usebackq tokens=2 delims=TAB " %%i in ("C:\TEST\test columns 2.txt") do (
findstr /c:"%%i" "C:\TEST\temp.txt"
if !errorlevel!==0 set /a count+=1
)
echo !count! match(es)
pause
del /q "C:\TEST\temp.txt"
您需要将路径替换为与您相关的路径。此外,您可以通过 嵌套 for
条件来更有效地做到这一点:
@echo off
setlocal enabledelayedexpansion
set count=0
for /f "usebackq tokens=2 delims=TAB " %%i in ("C:\TEST\test columns 1.txt") do (
for /f "usebackq tokens=2 delims=TAB " %%j in ("C:\TEST\test columns 2.txt") do (
if %%i==%%j set /a count+=1
)
)
echo !count! match(es)
pause