I need to sort a text file which has uneven width and spacing,with column 5 being descending, and column 6 and 7 as ascending, with sorted file in same format. Column 7 contains alphanumeric character.
GSASS 21321 5 10.000 Q 236333 AB5 4IW332 1111 2/24/2015
DSASS 53155 111100 1.000 B 237140 AB5 4IW332 3223 2/24/2015
GAA 43453 111190 2.000 B 237140 AB1 4IW332 2222 2/24/2015
AASAD 23173 111191 1.000 B 237140 AB11 4IW332 2222 2/24/2015
RASS 23173 2 4.000 Q 235445 AB5 4IW332 1114 2/24/2015
I know about sort-object and split cmdlets, but i am unable to end with required result. The nearby result i could get is from below command:
get-content C:/filename.txt| For each {"$(($_ -split '\s+',10)[0..9])"}|Sort-object {$_.split(" ")[+4,+5,+6]} > newfile.txt
The main issue with above one it removes the spacing in order to sort, and I need sorted file in same format. And column 7 is aplhanumeric, so it sort like AB1, AB11 over AB5.
Below are the stack-overflow links I could find useful: Extracting columns from text file using PowerShell PowerShell: How do I sort a text file by column? Powershell ,Read from a txt file and Format Data( remove lines, remove blank spaces in between)