PowerShell: How do I sort a text file by column? PowerShell: How do I sort a text file by column? powershell powershell

PowerShell: How do I sort a text file by column?


You can sort by an expression, split each line (space delimiter), cast the last item to system.double and sort on it:

Get-Content .\file.txt | Sort-Object { [double]$_.split()[-1] } -Descending


another variant:

gc c:\f1.txt | add-member scriptproperty sortby {$this.split()[-1]} {[double]$this} -pass | sort sortby -desc