如何从Windows命令行进行grep输出



>我在管理模式下使用 Windows 命令提示符 cmd 执行各种任务,例如查找 IP 地址接口名称等。当我发出一些命令时,例如 ipconfig/all

Windows IP Configuration
Host Name . . . . . . . . . . . . : 
Primary Dns Suffix  . . . . . . . : 
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : domain.name
Ethernet adapter Ethernet 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix  . : domain.name
Description . . . . . . . . . . . : Realtek PCIe GbE Family Controller #2
Physical Address. . . . . . . . . : 
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Ethernet adapter VMware Network Adapter VMnet1:
Connection-specific DNS Suffix  . : 
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1
Physical Address. . . . . . . . . : 
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : 
IPv4 Address. . . . . . . . . . . : 192.168.56.1(Preferred) 
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : 10 December 2019 22:10:04
Lease Expires . . . . . . . . . . : 11 December 2019 03:10:04
Default Gateway . . . . . . . . . : 
DHCP Server . . . . . . . . . . . : 192.168.56.254
DHCPv6 IAID . . . . . . . . . . . : 33574998
DHCPv6 Client DUID. . . . . . . . : 
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled
Ethernet adapter VMware Network Adapter VMnet8:
Connection-specific DNS Suffix  . : 
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
Physical Address. . . . . . . . . : 
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : 
IPv4 Address. . . . . . . . . . . : 192.168.136.1(Preferred) 
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : 10 December 2019 22:10:04
Lease Expires . . . . . . . . . . : 11 December 2019 03:10:04
Default Gateway . . . . . . . . . : 
DHCP Server . . . . . . . . . . . : 192.168.136.254
DHCPv6 IAID . . . . . . . . . . . : 268456022
DHCPv6 Client DUID. . . . . . . . : 
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
Primary WINS Server . . . . . . . : 192.168.136.2
NetBIOS over Tcpip. . . . . . . . : Enabled
Wireless LAN adapter Wi-Fi 2:
Connection-specific DNS Suffix  . : domain.name
Description . . . . . . . . . . . : D-Link DWA-131 Wireless N Nano USB Adapter(rev.E)
Physical Address. . . . . . . . . : 
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : 
IPv4 Address. . . . . . . . . . . : 192.168.1.14(Preferred) 
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : 10 December 2019 22:10:09
Lease Expires . . . . . . . . . . : 11 December 2019 22:10:12
Default Gateway . . . . . . . . . : 
192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.1
DHCPv6 IAID . . . . . . . . . . . : 353154770
DHCPv6 Client DUID. . . . . . . . : 
DNS Servers . . . . . . . . . . . : 109.169.85.7
8.8.8.8
NetBIOS over Tcpip. . . . . . . . : Enabled
Wireless LAN adapter Wi-Fi:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix  . : domain.name
Description . . . . . . . . . . . : Realtek RTL8723DE 802.11b/g/n PCIe Adapter
Physical Address. . . . . . . . . : 
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes

我在屏幕上得到很多输出。如果我只想要那些有物理特征的线条 文本输出或 say 行仅在输出中具有 DNS 服务器。那么有没有一个简单的方法可以做到 在Windows 10 cmd中对这些内容的grep。 或者假设在上面的输出中,我只想看到 Vmnet8 部分的输出

那我该怎么做呢?

我只想要那些有物理特征的行

ipconfig|findstr /r ":: [0-9]."

筛选包含::(对于 IPv6 地址(或<number><dot>(对于 IPv4 地址(的行

(正如你提到的,作为一个"Linux人" - 不要对findstrREGEX抱有太多期望。它只是真实 REGEX 的一小部分残缺子集 - 见findstr /?(

下载免费的MOBAXTERM,然后浏览Windows操作系统,就像使用Linux一样。然后你将能够使用grep等。

随着Windows子系统Linux(WSL(的引入,你可以直接在ipconfig上使用grep

**我对grep的了解有限。下面是一个基本的示例用法:

  1. 在经典的 Windows命令提示符下,运行:

    C:> ipconfig /all | wsl grep 'IPv4'

  2. Linux 终端(例如 WSL 上的 Ubuntu(上运行(注意.exe扩展(:

    $ ipconfig.exe /all | grep 'IPv4'

示例输出

IPv4 Address. . . . . . . . . . . : 192.198.100.1(Preferred)
IPv4 Address. . . . . . . . . . . : 192.198.15.9(Preferred)
IPv4 Address. . . . . . . . . . . : 192.198.89.1(Preferred)
...

最新更新