Reputation: 3
Im actually trying to sort a .txt file with a powershell script after a specific char ( " ____ " ) and after that those four underscore I need to sort, any tips or link that could help me ?
The file can look like this :
blablabla_12345____nameToSort
blablaree_53624____nameToSort
Actually the code look just like this :
Get-Content Desktop/test.txt | sort | get-unique > Desktop/result.txt
And so, it sort the text file by the first char and not the actual name Thanks for your help
Upvotes: 0
Views: 238
Reputation: 61068
You can sort on a calculated piece of the text like:
Get-Content -Path 'D:\Test\bla.txt' |
Sort-Object {($_ -split '_{4}')[-1]} -Unique |
Out-File -FilePath 'D:\Test\result.txt'
Upvotes: 2