gpt4 book ai didi

sorting - Powershell:按日期重新排列文件中的行

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

我有一个像这样的输入文件:
彼得·墨尔本,1982年3月3日
西蒙,悉尼,1990年2月21日
汤姆,阿德莱德,1980年2月2日

我想做的是按日期列重新排列文件的内容并将其保存到文件中。
喜欢:
汤姆,阿德莱德,1980年2月2日
彼得·墨尔本,1982年3月3日
西蒙,悉尼,1990年2月21日

整个过程应该在Powershell中完成。

干杯!

最佳答案

@vonPryz给出了一个很好的答案,您可以做的短一些。

# Read input data
$c = Import-Csv -Header @("Name","City","Date") c:\temp\data.txt -Delimiter ","

# Get the good globalization info
$oz = new-object Globalization.CultureInfo("en-AU")

#
$c | Sort-Object {[System.DateTime]::Parse($_.date, $oz)}

# Write output data
$d | Export-Csv c:\temp\datasSortedVyDate.csv -NoTypeInformation

关于sorting - Powershell:按日期重新排列文件中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16097725/

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