我正在尝试编写Windows批处理文件以获取给定输入的OUTPUT以下
输入:
//Dev-420/PAVAN/src/main/java/test/abcd/mnop/HealthCheck.java - edit change 1111111
//Dev-420/PAVAN/src/main/java/test/abcd/mnop/HealthStatus.java - edit change 1111111
//Dev-420/PAVAN/src/main/java/test/xyz/Relations.java - edit change 1111112
输出:
数组CHANGELIST应该只包含唯一值
[1111111, 1111112]
现在将其作为[1111111,1111111,1111112]
下面是我正在使用的脚本。 我确实找到了一种方法。
@echo off
set "File2Read=files_list.tmp"
set "FILENAME="
setlocal EnableDelayedExpansion
set /a count=0
set "BINARY_FILENAME="
set "replaceBinaryPath=target/classes/"
set "basePath=//ATT/Dev-420/PAVAN/src/main/java/"
for /f "delims=" %%a in ('Type "%File2Read%"') do (
set "line=%%a"
for /f "tokens=1,2,3,4,5 delims= " %%a in ("!line!") do (
set FILENAME=%%a
set CHANGELIST=%%e
)
set "BINARY_FILENAME=!FILENAME:%basePath%=%replaceBinaryPath%!"
if not !FILENAME!==!BINARY_FILENAME! (
set /a count+=1
set "CHANGELISTS[!count!]=!CHANGELIST!"
)
)
endLocal
请以某种方式帮助我,以便仅在CHANGELISTS
数组中插入唯一值。
非常感谢您的帮助!
答案 0 :(得分:0)
避免多行代码块时,测试/调试脚本要容易得多。我删除了冗余循环并剥离了多余的位。
@setlocal EnableExtensions EnableDelayedExpansion
@rem echo off
@set "_fileToRead=files_list.tmp"
@for /f "tokens=1,2,3,4,5" %%I in (%_fileToRead%) do @call :DoIt "%%I" %%M
@exit /b 0
:Append
@if "" equ "%_changeList%" (@set _changeList=%1) else (@set _changeList=%_changeList% %1)
@exit /b 0
:DoIt
@call :SetFound %2
@if %_found% equ false @call :Append %2
@rem This is where you do something with the path/file in %1
@echo %~1 %2
@echo %_changeList%
@exit /b 0
:SetFound
@set _found=false
@for /f "tokens=1" %%a in ("%_changeList%") do @if %%a equ %1 @set _found=true
@exit /b 0
使用您的测试数据生成此输出:
//Dev-420/PAVAN/src/main/java/test/abcd/mnop/HealthCheck.java 1111111
1111111
//Dev-420/PAVAN/src/main/java/test/abcd/mnop/HealthStatus.java 1111111
1111111
//Dev-420/PAVAN/src/main/java/test/xyz/Relations.java 1111112
1111111 1111112
应该足够容易使您建立起来。