【发布时间】:2017-09-17 21:38:19
【问题描述】:
有一个 xml 文件,我想使用批处理脚本将其提取到 excel 文件中。
文字:
<TableCell width="20" class="normal">10.0.0.1</TableCell>
<Paragraph>5900/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.1</TableCell>
<Paragraph>139/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.2</TableCell>
<Paragraph>445/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.3</TableCell>
<Paragraph>139/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.3</TableCell>
<Paragraph>445/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.2</TableCell>
<Paragraph>443/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.3</TableCell>
<Paragraph>1311/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.1</TableCell>
<Paragraph>1443/tcp</Paragraph></TableCell>
<TableCell width="20" class="normal">10.0.0.4</TableCell>
<Paragraph>443/tcp</Paragraph></TableCell>
目前出来的代码,还是卡在拆分部分,因为有错误
代码:
@ECHO OFF
SET LOCAL
SET "file=C:\Users\Intern3\Downloads\Nmap\Nex\1.txt"
FOR /F "usebackq tokens=1-4 delims=^>" %%a IN ("%file%") DO (
echo %%a %%b
CALL :process %%a %%b)
GOTO :eof
:process
echo %*
pause
ECHO %*|FIND "class" > NUL
IF NOT ERRORLEVEL 1 GOTO ip
GOTO :eof
:ip
FOR /F "tokens=* delims=^=" %%b IN (%*) DO (
pause
ECHO %%b, %%c, %%d)
GOTO :eof
现在代码中有回显,因为我想看看错误在哪里。
只有在读取ip地址时才会出现错误。但是对于港口来说,一切都找到了。
错误:
The system cannot find the file width
输出应该是这样的
示例输出:
10.0.0.1
5900/tcp
139/tcp
1443/tcp
10.0.0.2
445/tcp
443/tcp
10.0.0.3
139/tcp
1311/tcp
445/tcp
10.0.0.4
443/tcp
假定的输出。但我仍然坚持拆分IP地址。 请帮忙。谢谢
【问题讨论】:
-
我使用的工具绝对是错误的,我遇到了问题。请帮忙!您为什么要在批处理文件中执行此操作? Excel 将直接导入 XML,与使用批处理文件相比,使用 VBA 字符串函数和循环单元格可以更轻松地使用它。别再试图用锤子做手术了。
标签: xml windows batch-file scripting