如何组合两个不同的标记、delims 和 findstrs?

问题描述 投票:0回答:1

我有一个用于软件许可证使用的输出文本文件,其中显示大量信息,我想根据该行包含的内容提取每行的片段以简化输出。

这是我拥有的代码,它们工作得很好,除了我需要将它们组合起来,所以如果文本文件中的一行包含“maxReleaseNumber”,它会做一件事,但如果该行包含“internal Id”,它会做另一件事.

@ECHO OFF
SET InFile=C:\temp\ListUsers.txt

cd C:\Program Files\SoftwareSystemes\License Server\
LicSrv -admin -run "c XXlic4 1004; glu -feature XXX-FTXHDXMCE>%InFile%; glu -feature XXX-AMEMCE>>%InFile%; glu -feature XXX-MCE>>%InFile%; glu -feature XXX-HDXMCE>>%InFile%; glu -feature X3X>>%InFile%;quit" 

echo off


::These 2 lines are the codes I want combined, it only works right now if only one is off at a time.
for /f "tokens=1, 14, 15, 16, 17 delims= " %%a in ('type C:\temp\ListUsers.txt ^|findstr /c:"maxReleaseNumber"') do (echo %%a %%b %%c %%d %%e)

::for /f "tokens=13, 14, 15, 16, 17, 18, 21, 22, 24 delims=. " %%a in ('type C:\temp\ListUsers.txt ^|findstr /c:"internal Id"') do (echo %%g %%h %%i %%a %%b %%c %%d %%e %%f)

del %InFile%

Pause
windows batch-file token delimiter findstr
1个回答
0
投票

由于您没有向我们展示任何示例数据或告诉我们您到底希望从该数据中提取什么,所以这只是一个猜测:

for /f "tokens=1, 14, 15, 16, 17 delims= " %%a in ('type C:\temp\ListUsers.txt ^|findstr /c:"maxReleaseNumber"') do (
 echo %%a %%b %%c %%d %%e

 for /f "tokens=13, 14, 15, 16, 17, 18, 21, 22, 24 delims=. " %%A in ('type C:\temp\ListUsers.txt ^|findstr /c:"internal Id"') do (
  echo %%G %%H %%I %%A %%B %%C %%D %%E %%F
  echo ----------
  echo %%G %%H %%I %%A %%B %%C %%D %%E %%F %%a %%b %%c %%d %%e
  echo ----------
 )
)

...因为元变量区分大小写。

© www.soinside.com 2019 - 2024. All rights reserved.