[英]how to grep output from windows command line
I use windows command prompt cmd in admin mode for various task like finding ip address interface names etc. When I issue some command like ipconfig /all我在管理模式下使用 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
I get a lot of output on my screen.If I want only those lines which have physical addeess in text output or say line that have DNS Servers only in ouput.我的屏幕上有很多输出。如果我只想要那些在文本输出中有物理地址的行,或者说只有在输出中有 DNS 服务器的行。 Then is there an easy way to do a grep on these in outout in Windows 10 cmd.
那么有没有一种简单的方法可以在 Windows 10 cmd 中对这些 in outout 进行 grep。 Or suppose in above output I want to see only output for section Vmnet8
或者假设在上面的输出中我只想看到部分 Vmnet8 的输出
then how can I grep it?那我怎么才能grep呢?
I want only those lines which have physical addeess
我只想要那些有物理地址的线路
ipconfig|findstr /r ":: [0-9]\."
filters for lines that contain ::
(for IPv6 addresses) or <number><dot>
(for IPv4 addresses)包含
::
:(对于 IPv6 地址)或<number><dot>
(对于 IPv4 地址)的行的过滤器
(as you mentioned being a "Linux-Guy" - don't expect too much from findstr
REGEX. It's just a small crippled subset of real REGEX - see findstr /?
) (正如你提到的“Linux-Guy” - 不要对
findstr
REGEX 抱有太多期望。它只是真正 REGEX 的一小部分残缺的子集 - 请参阅findstr /?
)
Download the free MOBAXTERM then navigate through your windows OS same as if you are using Linux.下载免费的 MOBAXTERM,然后像使用 Linux 一样浏览您的 Windows 操作系统。 Then you will be able to use grep etc.
然后你将能够使用 grep 等。
With the introduction of Windows Subsystem for Linux ( WSL
), you can use grep
directly on ipconfig
.随着适用于 Linux的Windows 子系统(
WSL
) 的引入,您可以直接在ipconfig
上使用grep
。
** I have limited knowledge on grep
. **我对
grep
知识有限。 Here is a basic example usage:这是一个基本的示例用法:
On the classic Windows Command Prompt , run:在经典的 Windows命令提示符上,运行:
C:\\> ipconfig /all | wsl grep 'IPv4'
On a Linux Terminal ( eg Ubuntu on WSL ), run (notice the .exe
extension):在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)
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.