批量解析命令输出
Batch parse command output
我有以下命令和输出:
d:\adb>adb shell service call iphonesubinfo 1
Result: Parcel(
0x00000000: 00000000 0000000f 00350033 00380039 '........8.5.9.8.'
0x00000010: 00320037 00360030 00350032 00310034 '7.2.0.1.2.4.4.1.'
0x00000020: 00390039 00000039 '5.9.9... ')
如何解析它并在一行中仅获取 IMEI?
还有:
< waiting for device >
...
(bootloader) ---------------------------------------------------------
(bootloader) Device-ID
(bootloader) 2FC9A68923FD175AA6E13657181CA6AB
(bootloader) 4AE438F12376AFA85D0E3467AE83A752
(bootloader) ---------------------------------------------------------
OKAY [ 0.020s]
finished. total time: 0.020s
获取序列号为:2FC9A68923FD175AA6E13657181CA6AB4AE438F12376AFA85D0E3467AE83A752
请注意我在 "code"
中的 REM 评论
@echo off
REM Spliting the IMEI multiline output to lines
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`adb shell service call iphonesubinfo 1`) DO (
SET var!count!=%%F
SET /a count=!count!+1
)
REM From each output line of interest we take the IMEI "string" portion
for /f "tokens=6" %%G IN ("%var2%") DO SET v1=%%G
for /f "tokens=6" %%G IN ("%var3%") DO SET v2=%%G
for /f "tokens=4" %%G IN ("%var4%") DO SET v3=%%G
REM Stiching the IMEI parts to one string
SET imei=%v1%%v2%%v3%
SET imei=%imei:'=%
SET imei=%imei:.=%
ECHO %imei%
ENDLOCAL
我有以下命令和输出:
d:\adb>adb shell service call iphonesubinfo 1
Result: Parcel(
0x00000000: 00000000 0000000f 00350033 00380039 '........8.5.9.8.'
0x00000010: 00320037 00360030 00350032 00310034 '7.2.0.1.2.4.4.1.'
0x00000020: 00390039 00000039 '5.9.9... ')
如何解析它并在一行中仅获取 IMEI?
还有:
< waiting for device >
...
(bootloader) ---------------------------------------------------------
(bootloader) Device-ID
(bootloader) 2FC9A68923FD175AA6E13657181CA6AB
(bootloader) 4AE438F12376AFA85D0E3467AE83A752
(bootloader) ---------------------------------------------------------
OKAY [ 0.020s]
finished. total time: 0.020s
获取序列号为:2FC9A68923FD175AA6E13657181CA6AB4AE438F12376AFA85D0E3467AE83A752
请注意我在 "code"
中的 REM 评论@echo off
REM Spliting the IMEI multiline output to lines
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`adb shell service call iphonesubinfo 1`) DO (
SET var!count!=%%F
SET /a count=!count!+1
)
REM From each output line of interest we take the IMEI "string" portion
for /f "tokens=6" %%G IN ("%var2%") DO SET v1=%%G
for /f "tokens=6" %%G IN ("%var3%") DO SET v2=%%G
for /f "tokens=4" %%G IN ("%var4%") DO SET v3=%%G
REM Stiching the IMEI parts to one string
SET imei=%v1%%v2%%v3%
SET imei=%imei:'=%
SET imei=%imei:.=%
ECHO %imei%
ENDLOCAL