gpt4 book ai didi

powershell - 在列之间添加定界符,并在左侧删除日志文件时间

转载 作者:行者123 更新时间:2023-12-03 00:36:18 24 4
gpt4 key购买 nike

我对PowerShell和解析/格式化数据有疑问。

我目前有如下数据:

10:23:46   Starting execution of script
10:23:46 Default user will be svc_consumption
10:23:46 Checking Data Domain Available Space
10:23:48 Model number: DD890 - 07/15/2016 10:23:46 - 139.18.40.21 -
10:23:50 Model number: DD890 - 07/15/2016 10:23:46 - 103.153.18.28 -
10:23:52 Model number: DD890 - 07/15/2016 10:23:46 - 12.19.41.75 -

10:24:02 Model number: DD880 - 07/15/2016 10:23:46 - 103.6.28.71 -
10:24:04 Model number: DD890 - 07/15/2016 10:23:46 - 10.116.83.12 -
10:24:05 Model number: DD4500 - 07/15/2016 10:23:46 - 10.18.31.86 -
10:24:06 Model number: DD4500 - 07/15/2016 10:23:46 - 10.18.23.10 -

我想知道每个人的想法是如何通过删除日志时间并使用分号作为分隔符来解析此数据。
我尝试了几次,但是所有尝试都太复杂了。
有任何想法吗?

感谢所有提供帮助的人!

编辑:希望得到类似“DD890; 07/15/2016:10:23:46; 139.18.40.21”

最佳答案

我将为此使用正则表达式替换:

$inputFile = 'C:\path\to\your.log'
$outputFile =

$re = '([A-Z]{2}\d+) - (\d{2}/\d{2}/\d{4}) (\d{2}:\d{2}:\d{2}) - ' +
'(\d+\.\d+\.\d+\.\d+) -$'

(Get-Content 'C:\input.txt') -match $re -replace ".*$re", '$1;$2:$3;$4' |
Set-Content 'C:\output.txt'

如果您希望将其余内容保留在原处,而只是更改 DD890 - 07/15/2016 10:23:46 - 139.18.40.21 -子字符串的格式,请在替换搜索字符串中删除 -match操作和其他 .*:
(Get-Content 'C:\input.txt') -replace $re, '$1;$2:$3;$4' |
Set-Content 'C:\output.txt'

关于powershell - 在列之间添加定界符,并在左侧删除日志文件时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38401493/

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