gpt4 book ai didi

powershell - 根据Powershell中的列对文本文件进行排序

转载 作者:行者123 更新时间:2023-12-03 00:41:52 25 4
gpt4 key购买 nike

我试图根据InvokeID对以下日志文​​件进行排序。这是最后一列。列虽然没有标题,但我无法根据名称对其进行过滤。我试图用行中数字的位置过滤它,可惜没有找到解决方案

11:20:36:645 ra-agi Trace: Sending Query Request message to application gateway host.     11:20:36:645 ra-agi Trace:     ApplicationGatewayID = 5000  11:20:36:645 ra-agi Trace:     InvokeID =             11359032 
11:20:36:645 ra-agi Trace: Received Query Confirm message from application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5001 11:20:36:645 ra-agi Trace: InvokeID = 11359018
11:20:36:645 ra-agi Trace: Received Query Confirm message from application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5001 11:20:36:645 ra-agi Trace: InvokeID = 11359017
11:20:36:645 ra-agi Trace: Sending Query Request message to application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5000 11:20:36:645 ra-agi Trace: InvokeID = 11359033
11:20:36:645 ra-agi Trace: Received Query Confirm message from application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5000 11:20:36:645 ra-agi Trace: InvokeID = 11359032

最佳答案

日志中没有显示可识别的实际列,并且似乎在值前加上了大量空格。您可以将其视为Fixed-Width表并使用我的ConvertFrom-FixedWidth函数,但是下面的代码应该可以满足您的要求:

Get-Content -Path 'TheLogFile.log' | Sort-Object @{Expression = { [int]($_.Trim() -split '\s+')[-1] }}

结果:
11:20:36:645 ra-agi Trace: Received Query Confirm message from application gateway host.  11:20:36:645 ra-agi Trace:     ApplicationGatewayID = 5001  11:20:36:645 ra-agi Trace:     InvokeID =             11359017 
11:20:36:645 ra-agi Trace: Received Query Confirm message from application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5001 11:20:36:645 ra-agi Trace: InvokeID = 11359018
11:20:36:645 ra-agi Trace: Sending Query Request message to application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5000 11:20:36:645 ra-agi Trace: InvokeID = 11359032
11:20:36:645 ra-agi Trace: Received Query Confirm message from application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5000 11:20:36:645 ra-agi Trace: InvokeID = 11359032
11:20:36:645 ra-agi Trace: Sending Query Request message to application gateway host. 11:20:36:645 ra-agi Trace: ApplicationGatewayID = 5000 11:20:36:645 ra-agi Trace: InvokeID = 11359033

关于powershell - 根据Powershell中的列对文本文件进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60037083/

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