如何格式化文本文件上的批处理命令结果 [英] How to format batch command result on text file

查看:58
本文介绍了如何格式化文本文件上的批处理命令结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的批处理脚本检索计算机信息,

I am retrieving computer information using the batch script below,

(
    systeminfo | findstr /c:"Host Name" /c:"Domain" /c:"OS Name" /c:"OS Version" /c:"System Manufacturer" /c:"System Model" /c:"System type" /c:"Total Physical Memory" /c:"Available Physical Memory" 

    wmic bios get serialnumber

) > "getPCinfo.txt"

然后在文本文件上得到的结果是

then result on the text file is

Host Name:                 Host
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.16299 N/A Build 16299
System Manufacturer:       Dell Inc.
System Model:              Latitude 7480
BIOS Version:              Dell Inc. 1.7.3, 10/11/2017
Total Physical Memory:     8,077 MB
Available Physical Memory: 2,450 MB
Domain:                    Domain.Domain.Domain.net
S e r i a l N u m b e r     

 3 R K 5 M H 2               

我可以知道如何将序列号格式化为与以前的信息相同的格式:-

May I know how can I format the Serial Number into the same format as previous info as something like :-

S e r i a l N u m b e r :   3 R K 5 M H 2  

推荐答案

我不喜欢脚本中的行太长-概述太快了.
该批次使用findstr的默认RegEx模式,行的锚点以/B
开头 并用点代替搜索字符串中的空格.

I don't like overly long lines in scripts - you loose overview too fast.
This batch uses findstr's default RegEx mode, anchors at line begin with /B
and substitutes the spaces in the search strings with a dot.

:: Q:\Test\2018\06\22\Get-PCInfo.cmd
@Echo off
FOR /F "tokens=1,2 delims==" %%A IN ('
  wmic bios get serialnumber /value ^|find /I "serialnumber"
') DO For %%C in (%%B) Do Set "BIOS=%%A:              %%C"

Set "Find=Host.Name Domain OS.Name OS.Version System.Manufacturer"
Set "Find=%Find% System.Model System.type Total.Physical.Memory"
Set "Find=%Find% BIOS.Version Available.Physical.Memory"

( systeminfo | findstr /I /B "%Find%"
  Echo=%BIOS%
) >getPCinfo.txt

示例输出:

> type getPCinfo.txt
Host Name:                 HOST
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.16299 N/A Build 16299
System Manufacturer:       System manufacturer
System Model:              System Product Name
System Type:               x64-based PC
BIOS Version:              American Megatrends Inc. 1408   , 09/21/2010
Total Physical Memory:     24.566 MB
Available Physical Memory: 14.753 MB
Domain:                    Doamin
SerialNumber:              Number

这篇关于如何格式化文本文件上的批处理命令结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆