标题: [文本处理] BAT怎样把命令结果截取特定内容赋值给一个变量? [打印本页]
作者: xiayukun 时间: 2017-8-17 10:17 标题: BAT怎样把命令结果截取特定内容赋值给一个变量?
本帖最后由 pcl_test 于 2017-8-17 14:41 编辑
(ADDRESS = (PROTOCOL = TCP)(HOST = WIN-6GHP9BD30SV)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = WIN-6GHP9BD30SV)(PORT = 1521))
以上为命令结果,怎么获取两个端口号,然后赋值。比如:把两个端口号赋给PORT变量,以空格分开。PORT=1521 1521
作者: Batcher 时间: 2017-8-17 14:24
- @echo off
- setlocal enabledelayedexpansion
- set "port="
- REM 假设你运行的命令是 findstr /c:"PORT =" 1.txt
- for /f "delims=" %%a in ('findstr /c:"PORT =" 1.txt') do (
- set str=%%a
- set str=!str:~-15!
- set str=!str:*PORT=!
- set str=!str:~3,-2!
- set port=!port! !str!
- )
- set port=!port:~1!
- echo !port!
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |