跳过批处理脚本中的多行

ont*_*cks 3 windows cmd batch-file command-prompt

我只想从命令的输出中打印出某一行。让我们以ipconfig命令为例。这将返回很多行。

Windows IP Configuration


Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : ab80::456d:123e:5ae5:9ab6%15
   IPv4 Address. . . . . . . . . . . : 192.168.1.33
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter Local Area Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
Run Code Online (Sandbox Code Playgroud)

我只想打印第 11 行。

我尝试了以下

FOR /F "skip=10 delims=" %G IN ('IPCONFIG') DO @ECHO %G
Run Code Online (Sandbox Code Playgroud)

这仅跳过前 10 行并打印其余行。

   Default Gateway . . . . . . . . . : 192.168.1.1
Ethernet adapter Local Area Connection:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
Run Code Online (Sandbox Code Playgroud)

如何打印第 11 行?

MC *_* ND 5

离开循环

FOR /F "skip=10 delims=" %G IN ('IPCONFIG') DO @ECHO %G & goto done
:done
Run Code Online (Sandbox Code Playgroud)

编辑从单个命令行获取命令输出中的第 11 行

for /f "tokens=1,* delims=:" %a in ('ipconfig^|findstr /n "^"^|findstr /l /b /c:"11:"') do echo %b
Run Code Online (Sandbox Code Playgroud)

执行命令,对输出进行编号,检索所需的行,拆分初始编号并回显其余部分

set "x=1" & for /f "skip=10 delims=" %a in ('ipconfig') do @(if defined x (set "x=" & echo %a))
Run Code Online (Sandbox Code Playgroud)

设置标志变量,执行命令,跳过前 10 行,如果设置了标志,则对每一行清除标志并回显该行