Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 将数组元素与特定字符串进行比较_Batch File - Fatal编程技术网

Batch file 将数组元素与特定字符串进行比较

Batch file 将数组元素与特定字符串进行比较,batch-file,Batch File,我正在用特定字符串逐行读取文本文件,然后将每个字符串存储在数组中。现在我必须将每个数组元素与特定字符串进行比较。我已尝试使用以下代码 setlocal enabledelayedexpansion enableextensions for /F "tokens=2,3 delims= " %%a in ('findstr "associationMaxRtx maxIncomingStream maxOutgoingStream initialAdRecWin maxUserdataSize m

我正在用特定字符串逐行读取文本文件,然后将每个字符串存储在数组中。现在我必须将每个数组元素与特定字符串进行比较。我已尝试使用以下代码

setlocal enabledelayedexpansion enableextensions
for /F "tokens=2,3 delims= " %%a in ('findstr "associationMaxRtx maxIncomingStream maxOutgoingStream initialAdRecWin maxUserdataSize mBuffer nThreshold PathMaxRtx maxInitialRtrAtt minimumRto maximumRto initialRto rtoAlphaIndex tSack" C:\Users\ephajin\logs.txt') do (
     set /A count+=1
     set vartmp1=%%a
     set vartmp2=%%b
     set "array[!count!]="%%a %%b""
)

(FOR /L %%a IN (1,1,%count%) DO SET "result=!result! !array[%%a]!"
if %result% == "associationMaxRtx 8"(
echo no need of modification) > result.txt                                   
 get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17  maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack  
但在结果文件中,我收到以下输入:

 get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17  maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack  
在结果文件中,所有数组元素都显示在一行中,原因我不知道,但实际上如下所示:

 get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17  maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack  
array[0]=get .
array[1]=associationMaxRtx 8   
array[2]=associationMaxRtx 8 

依此类推。我必须将每个数组元素与特定字符串进行比较,例如数组[1]=“associationMaxRtx 8”,然后打印一条消息。如何执行此操作,请帮助我

我认为上面缺少一段代码,但为了删除生成的
SET
语句中的额外引号,这将起作用:

 get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17  maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack  
(FOR /f "tokens=1* delims==" %%a  IN ('set array[') DO SET "result=%%~b"
ECHO "%result%" ) > result.txt
通过在
b
之前添加
~
符号(使其成为
%%~b
),围绕
%%b
的前导引号和尾随引号扩展为

 get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17  maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack  
这将产生(例如):

 get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17  maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack  
设置“结果=索引3”

 get . associationMaxRtx 8 associationMaxRtx 8 get . maxIncomingStream 17  maxIncomingStream 17 get . maxOutgoingStream 17 maxOutgoingStream 17 get . initialAdRecWin 32768 initialAdRecWin 32768 maxUserDataSize 1480 maxUserDataSize 1480 get . mBuffer 256 mBuffer 256 get . nThreshold 192 switchbackMinThreshold 1 nThreshold 192 switchbackMinThreshold 1 get . get . maxInitialRtrAtt 8 maxInitialRtrAtt 8 get . minimumRto 10 minimumRto 10 get . maximumRto 40 maximumRto 40 get . initialRto 20 initialRto 20 get . rtoAlphaIndex 3 rtoAlphaIndex 3 get . tSack 4 tSack 4 get tSack  

请给你提到的问题加一个链接。另外,请格式化代码。有人能帮我回答这个问题吗