使用批处理显示文本文件中特定行之后的所有行
这是我的代码。
@ECHO OFF
systeminfo > C:\SystemInfo1.txt
findstr /C:"OS Name:" /C:"OS Version:" /C:"OS Manufacturer:" /C:"Original Install Date:" /C:"System Boot Time:" /C:"System Manufacturer:" /C:"System Model:" /C:"System Type:" /C:"Processor(s):" /C:"System Locale:" /C:"Input Locale:" /C:"Time Zone:" /C:"NetWork Card" C:\SystemInfo1.txt > c:\SystemInfo.txt
DEL C:\SystemInfo1.txt
c:\SystemInfo.txt
EXIT
此代码的作用是仅显示文本文件“Systeminfo1.txt”中我需要的选定内容(如果您在显示网卡详细信息的末尾看到系统信息文件)。但通过这段代码我只得到第一行。
实际系统信息:
Host Name: BLRPN0W01085
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 3 Build 2600
OS Manufacturer: Microsoft Corporation
OS Configuration: Member Workstation
OS Build Type: Uniprocessor Free
Registered Owner: Admin
Registered Organization: Thomson Reuters
Original Install Date: 8/31/2011, 10:46:03 AM
System Up Time: 0 Days, 10 Hours, 19 Minutes, 2 Seconds
System Manufacturer: Dell Inc.
System Model: OptiPlex 755
System type: X86-based PC
Processor(s): 1 Processor(s) Installed.
[01]: x86 Family 6 Model 23 Stepping 6 GenuineIntel ~2992 Mhz
BIOS Version: DELL - 15
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\system32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (GMT) Casablanca
Total Physical Memory: 2,014 MB
Available Physical Memory: 772 MB
Virtual Memory: Max Size: 2,048 MB
Virtual Memory: Available: 2,008 MB
Virtual Memory: In Use: 40 MB
Page File Location(s): C:\pagefile.sys
Domain: tfcorp.tfn.com
Logon Server: \\INKABAN1DIR01
Hotfix(s): 319 Hotfix(s) Installed.
[01]: File 1
[02]: File 1
[03]: File 1
[04]: File 1
[05]: File 1
[06]: File 1
[07]: File 1
[08]: File 1
[09]: File 1
[10]: File 1
[11]: File 1
[12]: File 1
[13]: File 1
[14]: File 1
[15]: File 1
[16]: File 1
[17]: File 1
[18]: File 1
[19]: File 1
[20]: File 1
[21]: File 1
[22]: File 1
[23]: File 1
[24]: File 1
[25]: File 1
[26]: File 1
[27]: File 1
[28]: File 1
[29]: File 1
[30]: File 1
[31]: File 1
[32]: File 1
[33]: File 1
[34]: File 1
[35]: File 1
[36]: File 1
[37]: File 1
[38]: File 1
[39]: File 1
[40]: File 1
[41]: File 1
[42]: File 1
[43]: File 1
[44]: File 1
[45]: File 1
[46]: File 1
[47]: File 1
[48]: File 1
[49]: File 1
[50]: File 1
[51]: File 1
[52]: File 1
[53]: File 1
[54]: File 1
[55]: File 1
[56]: File 1
[57]: File 1
[58]: File 1
[59]: File 1
[60]: File 1
[61]: File 1
[62]: File 1
[63]: File 1
[64]: File 1
[65]: File 1
[66]: File 1
NetWork Card(s): 1 NIC(s) Installed.
[01]: Intel(R) 82566DM-2 Gigabit Network Connection
Connection Name: Local Area Connection
DHCP Enabled: Yes
DHCP Server: 10.136.193.51
IP address(es)
[01]: 10.136.208.125
我的代码显示的内容:
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 3 Build 2600
OS Manufacturer: Microsoft Corporation
Original Install Date: 8/31/2011, 10:46:03 AM
System Manufacturer: Dell Inc.
System Model: OptiPlex 755
Processor(s): 1 Processor(s) Installed.
BIOS Version: DELL - 15
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (GMT) Casablanca
NetWork Card(s): 1 NIC(s) Installed.
缺少什么:
[01]: Intel(R) 82566DM-2 Gigabit Network Connection
Connection Name: Local Area Connection
DHCP Enabled: Yes
DHCP Server: 10.136.193.51
IP address(es)
[01]: 10.136.208.125
我如何获取缺少什么?顺便说一句,有谁知道为什么 BIOS 显示为“DELL - 15”?这仅适用于 XP。
This is my code.
@ECHO OFF
systeminfo > C:\SystemInfo1.txt
findstr /C:"OS Name:" /C:"OS Version:" /C:"OS Manufacturer:" /C:"Original Install Date:" /C:"System Boot Time:" /C:"System Manufacturer:" /C:"System Model:" /C:"System Type:" /C:"Processor(s):" /C:"System Locale:" /C:"Input Locale:" /C:"Time Zone:" /C:"NetWork Card" C:\SystemInfo1.txt > c:\SystemInfo.txt
DEL C:\SystemInfo1.txt
c:\SystemInfo.txt
EXIT
What this code does is displays only the selected content i need from the text file 'Systeminfo1.txt' if you see your system info file at the end the Network Card details are displayed. But with this code i get only the first line.
Actual SystemInfo:
Host Name: BLRPN0W01085
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 3 Build 2600
OS Manufacturer: Microsoft Corporation
OS Configuration: Member Workstation
OS Build Type: Uniprocessor Free
Registered Owner: Admin
Registered Organization: Thomson Reuters
Original Install Date: 8/31/2011, 10:46:03 AM
System Up Time: 0 Days, 10 Hours, 19 Minutes, 2 Seconds
System Manufacturer: Dell Inc.
System Model: OptiPlex 755
System type: X86-based PC
Processor(s): 1 Processor(s) Installed.
[01]: x86 Family 6 Model 23 Stepping 6 GenuineIntel ~2992 Mhz
BIOS Version: DELL - 15
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\system32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (GMT) Casablanca
Total Physical Memory: 2,014 MB
Available Physical Memory: 772 MB
Virtual Memory: Max Size: 2,048 MB
Virtual Memory: Available: 2,008 MB
Virtual Memory: In Use: 40 MB
Page File Location(s): C:\pagefile.sys
Domain: tfcorp.tfn.com
Logon Server: \\INKABAN1DIR01
Hotfix(s): 319 Hotfix(s) Installed.
[01]: File 1
[02]: File 1
[03]: File 1
[04]: File 1
[05]: File 1
[06]: File 1
[07]: File 1
[08]: File 1
[09]: File 1
[10]: File 1
[11]: File 1
[12]: File 1
[13]: File 1
[14]: File 1
[15]: File 1
[16]: File 1
[17]: File 1
[18]: File 1
[19]: File 1
[20]: File 1
[21]: File 1
[22]: File 1
[23]: File 1
[24]: File 1
[25]: File 1
[26]: File 1
[27]: File 1
[28]: File 1
[29]: File 1
[30]: File 1
[31]: File 1
[32]: File 1
[33]: File 1
[34]: File 1
[35]: File 1
[36]: File 1
[37]: File 1
[38]: File 1
[39]: File 1
[40]: File 1
[41]: File 1
[42]: File 1
[43]: File 1
[44]: File 1
[45]: File 1
[46]: File 1
[47]: File 1
[48]: File 1
[49]: File 1
[50]: File 1
[51]: File 1
[52]: File 1
[53]: File 1
[54]: File 1
[55]: File 1
[56]: File 1
[57]: File 1
[58]: File 1
[59]: File 1
[60]: File 1
[61]: File 1
[62]: File 1
[63]: File 1
[64]: File 1
[65]: File 1
[66]: File 1
NetWork Card(s): 1 NIC(s) Installed.
[01]: Intel(R) 82566DM-2 Gigabit Network Connection
Connection Name: Local Area Connection
DHCP Enabled: Yes
DHCP Server: 10.136.193.51
IP address(es)
[01]: 10.136.208.125
What my code displays:
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 3 Build 2600
OS Manufacturer: Microsoft Corporation
Original Install Date: 8/31/2011, 10:46:03 AM
System Manufacturer: Dell Inc.
System Model: OptiPlex 755
Processor(s): 1 Processor(s) Installed.
BIOS Version: DELL - 15
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (GMT) Casablanca
NetWork Card(s): 1 NIC(s) Installed.
What is missing:
[01]: Intel(R) 82566DM-2 Gigabit Network Connection
Connection Name: Local Area Connection
DHCP Enabled: Yes
DHCP Server: 10.136.193.51
IP address(es)
[01]: 10.136.208.125
How do i get What is missing? BTW does anyone know why BIOS is shown as 'DELL - 15' ?? this is only with XP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们开始吧:
如果您确定只有一个 NIC(网卡),那么您可以删除“&”。从“FOR 语句”末尾转到剩余',并删除标签“:remainder”。
Here we go:
If you know for sure there is only ever going to be ONE NIC (network card) then you can remove the '& goto remainder' from the end of the 'FOR-statement' and remove the label ':remainder'.
仅使用“findstr”不可能完成您想要的操作,因为您需要根据上下文选择行(即第一个网卡后面的缩进行)。使用 perl、awk、ruby 或其他脚本语言来完成此操作很简单。
想到一种只用 Windows 的东西来做你想做的事情的方法,我想到了 Javascript。请注意,Javascript 不是我的强项,这可能可以做得更好,但假设您想要“NetWork Cards”之后的所有行,这应该可行:
放入文件中(例如:filter.js):
将其 批处理文件,执行:
It's not possible to do what you want using only "findstr", because you need to select lines based on their context (i.e. The indented lines that follow the first network card). It's trivial to do it using perl, awk, ruby or other scripting languages.
Thinking of a way to do what you want with Windows stuff only, i thought of Javascript. Be aware that Javascript is not my forte, and this can probably be made better, but assuming you want all the lines after "NetWork Cards", this should work:
put this in a file (e.g.: filter.js):
The from your batch file, do:
字符串匹配仅限于单行(即回车符之间的内容)。因此您需要将缺少的标识符添加到搜索字符串列表中。
您会注意到这也会在您的处理器上带来额外的信息,因为 [01] 也与之匹配。如果您认为一个盒子可能有多个网卡,您也可以搜索 [02]。
如果您只想在它存在时搜索它,那么您将需要使用第一次运行的 systeminfo 输出作为另一个搜索文件的输入。例如,第一次运行输出将告诉您
1 NIC(s) Installed
或2 NIC(s) Installed
然后您需要使用for
来解析它code> 循环和字符匹配以获取安装的网卡的确切数量,然后使用它再次搜索 systeminfo。string match is limited to a single line (ie what's between carriage returns). so you will need to add the missing identifiers to your list of search strings.
you'll notice this will bring in extra info on your processor too because [01] matches there too. if you think a box might have more than one nic you could search for [02] also.
if you only want to search this when it's there then you will need to use your first run of systeminfo output as input for another search file. eg, first run output will tell you
1 NIC(s) Installed
or2 NIC(s) Installed
You will then need to parse that with afor
loop and character matching to get the exact number of nics installed then search systeminfo again using that.