用换行符批量解析,然后用冒号作为定界符

时间:2018-09-21 07:43:15

标签: batch-file confluence

我想在Windows批处理文件中解析命令的结果。我正在使用confluence-cli

命令cmd.exe /c confluence.bat --action getPage --title 'My title' --space XXX返回的结果与此类似:

Data for page with id: 123456789

Page id . . . . . . . . . . . : 123456789
Title . . . . . . . . . . . . : My title
Space key . . . . . . . . . . : XXX
Space name  . . . . . . . . . : XXX
Space home page id  . . . . . : 987654321
Space home page title . . . . : XXX
Parent id . . . . . . . . . . : 987654321
Parent title  . . . . . . . . : My parent title
Creator . . . . . . . . . . . : user1
Created . . . . . . . . . . . : 11/09/18 10:10
Modifier  . . . . . . . . . . : user1
Modified  . . . . . . . . . . : 11/09/18 10:14
Version . . . . . . . . . . . : 1
Version message . . . . . . . :
Content type  . . . . . . . . : page
Status  . . . . . . . . . . . : current
Is home page  . . . . . . . . : No
URL . . . . . . . . . . . . . : https://XXX.atlassian.net/wiki/spaces/XXX/pages/123456789

我想获取页面ID字段(123456789)或URL字段(https://XXX.atlassian.net/wiki/spaces/XXX/pages/123456789)。 我尝试过与此命令类似的命令,但到目前为止还没有运气:

@ECHO OFF
SETLOCAL
set getPage="cmd.exe /c confluence.bat --action getPage --title 'My title' --space XXX"
FOR /f "eol=#tokens=0delims=:2" %%a IN ('%getPage% /i0 %1 ^|find "id: "') DO SET /a pageId=%%a
ECHO Page id is %pageId%
GOTO :EOF

我很难在bat中操纵for表达式来实现我想要的功能,尤其是使用tokendelim表达式时。

0 个答案:

没有答案
相关问题