Bre*_*her 1 sorting powershell
我有一个这样的输入文件:
Peter,Melbourne,30.5.1982
Simon,Sydney,21.2.1990
Tom,Adelaide,22.9.1980
我想要做的是按日期列重新排序文件的内容并将其保存到文件中。
喜欢:
汤姆,阿德莱德,22.9.1980
彼得,墨尔本,30.5.1982
西蒙,悉尼,21.2.1990
整个事情应该在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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2607 次 |
| 最近记录: |