在powershell中尝试排序来自winget list
的输出时,我没有得到预期的输出。未对Id
列进行排序。
# winget list | Sort-Object -Property Id
ScreenToGif NickeManarin.ScreenToGif 2.37.1 winget
Microsoft Visual C++ 2015-2019 Redist… Microsoft.VCRedist.2015+.x64 14.28.29325.2 14.34.318… winget
paint.net {28718A56-50EF-4867-B4C8-0860228B5EC9} 4.3.8
Python 3.10.0 (64-bit) {21b42743-c8f9-49d7-b8b6-b5855317c7ed} 3.10.150.0
Microsoft Support and Recovery Assist… 0527a644a4ddd31d 17.0.7018.4
-----------------------------------------------------------------------------------------------------------------------
Name Id Version Available Source
Paint 3D Microsoft.MSPaint_8wekyb3d8bbwe 6.2009.30067.0
Microsoft .NET SDK 6.0.402 (x64) Microsoft.DotNet.SDK.6 6.0.402 winget
3D Viewer Microsoft.Microsoft3DViewer_8wekyb3d8… 7.2010.15012.0
Microsoft Sticky Notes Microsoft.MicrosoftStickyNotes_8wekyb… 3.8.8.0
问:如何根据powershell中的winget list
列对Id
输出进行排序?
我希望看到类似于Bash sort -k <column-number>
的powershell解决方案,以便对任何列进行排序。我不明白为什么powershell中没有这个明显的函数?
发布于 2022-11-01 14:55:09
它输出文本,而不是像"Id“这样的属性的对象。这个程序的输出不是很聪明。看起来它输出了一些特殊的字符,比如…
(U+2026水平省略号)。我想到的第一件事是切断前39个字符,然后按第40列排序,从Id开始。这应该类似于unix中的排序-k。我相信winget的powershell版本将在未来问世。用空格替换非ascii并跳过前4行。
# or -creplace '\P{IsBasicLatin}'
(winget list) -replace '[^ -~]',' ' | select-object -skip 4 |
sort-object { $_.substring(39) }
Python 3.10.0 (64-bit) {21b42743-c8f9-49d7-b8b6-b5855317c7ed} 3.10.150.0
paint.net {28718A56-50EF-4867-B4C8-0860228B5EC9} 4.3.8
Microsoft Support and Recovery Assist 0527a644a4ddd31d 17.0.7018.4
Name Id Version Available Source
ScreenToGif NickeManarin.ScreenToGif 2.37.1 winget
Microsoft .NET SDK 6.0.402 (x64) Microsoft.DotNet.SDK.6 6.0.402 winget
3D Viewer Microsoft.Microsoft3DViewer_8wekyb3d8 7.2010.15012.0
Microsoft Sticky Notes Microsoft.MicrosoftStickyNotes_8wekyb 3.8.8.0
Paint 3D Microsoft.MSPaint_8wekyb3d8bbwe 6.2009.30067.0
Microsoft Visual C++ 2015-2019 Redist Microsoft.VCRedist.2015+.x64 14.28.29325.2 14.34.318 winget
https://stackoverflow.com/questions/74276422
复制相似问题