gpt4 book ai didi

file - 在powershell中删除回车

转载 作者:行者123 更新时间:2023-12-02 22:47:27 25 4
gpt4 key购买 nike

我在删除文本文件中的回车时遇到问题。我只想为“消息”删除回车。我需要将“消息”内容放在一行上。

我的输入看起来像:

TimeCreated      : 08/04/2014 22:31:15
LevelDisplayName : Information
Id : 50065
Message : DHCP a trouvé dans le cache une corespondance pour l’identificateur
(Service Set Identifier) Livebox-816F (valeur hexadécimale de
l’identificateur SSID : C496674) pour la carte réseau dont l’adresse
réseau est 0x0C

我想出了这行代码,但它不起作用:

$MyObject = Get-WinEvent -LogName 'Microsoft-Windows-Dhcp-Client/Admin' | Where-Object {$_.TimeCreated -ge $lastsevendays} | Select 'TimeCreated', 'LevelDisplayName', 'ID', @{n='Message';e={$_.Message -replace '`r', " "}}, $Size 
$MyObject > $SourceFile

非常感谢!

最佳答案

试试这个(折叠在 pipe 上以便于阅读):

$MyObject = Get-WinEvent -LogName 'Microsoft-Windows-Dhcp-Client/Admin' |
Where-Object {$_.TimeCreated -ge $lastsevendays} |
Select 'TimeCreated', 'LevelDisplayName', 'ID', @{n='Message';e={$_.Message -replace '\r', " "}}

$MyObject > $SourceFile

Powershell 解析器中的转义字符是反引号,但这些规则不适用于 -Replace 的正则表达式参数。那里你必须使用正则表达式解析规则,回车是 '\r'

注意:如果你想把它全部作为一行,你还必须替换换行符,所以你的替换将是 '\r\n',''

关于file - 在powershell中删除回车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22948485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com