首页 > 解决方案 > 如何使用 Powershell 从字段的多行数据中获取 .log 文件中的单行数据

问题描述

我正在从下面的查询生成日志文件。对于“描述”字段,我有多行数据并试图在单行中获取它。

示例“描述”:“测试示例应用程序

                     with different entries 
                     and functionalities."

获取团队 | foreach {​​​​</p>

选择 $DisplayName =$。DisplayName, $Description = @{​​​​'Name' = 'Description' ; 'Expression' = {​​​​ $ .Description.Split([System.Environment]::NewLine) -join '' }​​​​ }​​​​</p>

$outtemp= $DistplayName+"^^"+$描述

$outtemp |Out-File -encoding UTF8 "D:\Sample.log" -Append }

**在日志文件中得到以下输出**

Team1^^System.Collections.Hashtable

Team2^^System.Collections.Hashtable

在 Sample.log 文件中,获取“System.Collections.Hashtable”而不是 Description 值。

期望 sample.log 文件中的以下输出:

Team1^^使用不同的条目和功能测试示例应用程序

你能帮我解决这个问题吗?

标签: powershell

解决方案


这就是你所追求的吗?(像浏览器一样规范化字符串):

"Testing sample application 


with different entries 
and functionalities." -replace '\s+', ' '

结果:

Testing sample application with different entries and functionalities.

推荐阅读