从行 Batch Windows 7 中提取字母数字字符串
Extract alphanumeric string from line Batch Windows 7
我正在处理将自动连接所选设备的批处理文件。这是我的脚本的开头:
echo This is the list of connected devices:
adb devices -l | findstr "[0-9]"|find /N " "
set /P device= Select the device you would like to connect to:
这是 Windows 命令提示符中的输出:
[1]350800651 device asdsffas
[2]07ea9b921 device iwoequeo
我现在正在尝试的是仅从设备(350800651
或 07ea9b921
)获取 ID 号,这将是所选行(1
或2
在示例中)。关于我该怎么做的任何想法?我试过 findstr
+ 正则表达式,但它总是给我完整的行...
根据现已关闭的问题 link,已经有一个 link 编辑的答案。
然而,还有另一种简单的解决方法...不是最好的,但可能适合您。
@echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims=] " %%i in ('adb devices -l ^| findstr "[0-9]"|find /N " "') do (
set /p "result=Do you want to select device %%i [Y/N]: "
if /i "!result!"=="Y" "set device=%%i" & goto next
)
:next
echo do something else here with %device%
我正在处理将自动连接所选设备的批处理文件。这是我的脚本的开头:
echo This is the list of connected devices:
adb devices -l | findstr "[0-9]"|find /N " "
set /P device= Select the device you would like to connect to:
这是 Windows 命令提示符中的输出:
[1]350800651 device asdsffas [2]07ea9b921 device iwoequeo
我现在正在尝试的是仅从设备(350800651
或 07ea9b921
)获取 ID 号,这将是所选行(1
或2
在示例中)。关于我该怎么做的任何想法?我试过 findstr
+ 正则表达式,但它总是给我完整的行...
根据现已关闭的问题 link,已经有一个 link 编辑的答案。
然而,还有另一种简单的解决方法...不是最好的,但可能适合您。
@echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims=] " %%i in ('adb devices -l ^| findstr "[0-9]"|find /N " "') do (
set /p "result=Do you want to select device %%i [Y/N]: "
if /i "!result!"=="Y" "set device=%%i" & goto next
)
:next
echo do something else here with %device%