【发布时间】:2018-07-01 10:17:50
【问题描述】:
我想在powershell中将一个文本文件处理成格式良好的HTML表格,下面是文件内容-
Machine ID Proc Name Proc Inst Status Comment
----------------------------------------------------------------------
1 BG 1 RUNNING BG process started
1 BG 2 RUNNING BG process started
1 BG 3 RUNNING BG process started
1 BGPREDICT 1 RUNNING BG process started
1 DLMGR 1 RUNNING DLMGR process started
1 IAPJMS 1 NOT RUNNING
1 RPCBG 1 RUNNING RPCBG process started
1 RPC_TCP_LI 1 RUNNING RPC listener process started
1 RPC_UDP_LI 1 RUNNING RPC listener process started
1 SPO 1 RUNNING SPO Server process started
1 SPO 2 RUNNING SPO Server process started
1 WIS 1 RUNNING WIS process started
1 WIS 2 RUNNING WIS process started
1 WIS 3 RUNNING WIS process started
1 WIS 4 RUNNING WIS process started
1 WIS 5 RUNNING WIS process started
1 WIS 6 RUNNING WIS process started
1 WISMBD 1 RUNNING WISMBD process started
1 WISMBD 2 RUNNING WISMBD process started
1 WQS 1 RUNNING WQS process started
Timed out waiting for system status response.
我无法转换,因为它们看起来与 HTML 表格形式相同,但通过使用下面的 sn-p- 将所有内容放在每行的单个单元格中-
Get-Content $env:TEMP\stat.txt|ConvertTo-HTML -Property
@{Label='Text';Expression={$_}}
来自文本文件的标题应与其余的 HTML 表格中的相同,所有应分别与每个单元格一样对待
请帮助我实现这一目标。
【问题讨论】:
-
您首先必须将文本文件拆分为适当的列,我看到的唯一共同点是拆分多个空格,即使使用空尾列也很难做到这一点。