sort a file by grouping column

Question!

I have a file like the following:

PSG1 B41M 3

PSG1 G03G 1

PSG1 C09D 2

PSG2 H01L 4

PSG2 C08L 3

PSG10 H01B 2

PSG10 C08J 4

I want to sort the values in the third column but only when they have the same PSG. For the given example, I want the output file:

PSG1 B41M 3

PSG1 C09D 2

PSG1 G03G 1

PSG2 H01L 4

PSG2 C08L 3

PSG10 C08J 4

PSG10 H01B 2

I tried to sort the file based on the first and third column using command sort but it does not work as PSG10 appears exactly after PSG1 (before PSG2).

Any other ideas? I do not care if it is a script or Java code

Thank you.

By : Anastasia


Answers

I think you could use Map



This video can help you solving your question :)
By: admin