写一个bat程序将txt文档中所有ip_prefix的值提取出来
以下是一个用于提取txt文档中所有ip_prefix值的批处理程序:
@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
if exist "%outputFile%" del "%outputFile%"
for /f "tokens=*" %%a in ('type "%inputFile%"') do (
set line=%%a
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:" %%b in ("!line!") do (
if "%%b"=="ip_prefix" (
echo %%c>> "%outputFile%"
)
)
endlocal
)
echo "提取完成!"
endlocal
请按照以下步骤操作:
-
创建一个新的文本文件,将以上批处理程序复制粘贴到该文件中,并将文件保存为
extract_ip.bat。 -
将要提取ip_prefix值的文本文件重命名为
input.txt,并将其与extract_ip.bat文件放在同一个目录下。 -
双击运行
extract_ip.bat。 -
提取的ip_prefix值将会保存在名为
output.txt的文件中。
请确保 input.txt 文件的格式如下所示:
ip_prefix: 192.168.0.1
ip_prefix: 10.0.0.1
ip_prefix: 172.16.0.1
提取的ip_prefix值将会写入 output.txt 文件中:
192.168.0.1
10.0.0.1
172.16.0.1
请注意,以上程序假设每行只包含一个 ip_prefix 值,并且该值位于 : 字符之后。如果您的文本文件格式不同,请根据实际情况进行相应的修改
原文地址: http://www.cveoy.top/t/topic/iL9e 著作权归作者所有。请勿转载和采集!