My input may be any of the given two types.
First one
Each field is of width 20
2019 Autumn CS 753 6 Department elective AB
2019 Autumn CS 490 6 Honors core CC
2019 Autumn CS 492 6 Honors core FR
2019 Autumn CS 747 6 Department elective FF
2019 Autumn ES 200 3 Basic Sciences BC
Second one
^[[40m^[[33m 2019 Autumn CS 753 6 Department elective AB^[(B^[[m
^[[40m^[[37m 2019 Autumn CS 490 6 Honors core CC^[(B^[[m
^[[40m^[[37m 2019 Autumn CS 492 6 Honors core FR^[(B^[[m
^[[40m^[[33m 2019 Autumn CS 747 6 Department elective FF^[(B^[[m
^[[40m^[[36m 2019 Autumn ES 200 3 Basic Sciences BC^[(B^[[m
first file with color
I want to sort them with respect to third field that is field containing CS 490 etc.
Coloured inputs should give coloured outputs.
Expected output for input 1
2019 Autumn CS 490 6 Honors core CC
2019 Autumn CS 492 6 Honors core FR
2019 Autumn CS 747 6 Department elective FF
2019 Autumn CS 753 6 Department elective AB
2019 Autumn ES 200 3 Basic Sciences BC
Likewise for input 2
^[[40m^[[37m 2019 Autumn CS 490 6 Honors core CC^[(B^[[m
^[[40m^[[37m 2019 Autumn CS 492 6 Honors core FR^[(B^[[m
^[[40m^[[33m 2019 Autumn CS 747 6 Department elective FF^[(B^[[m
^[[40m^[[33m 2019 Autumn CS 753 6 Department elective AB^[(B^[[m
^[[40m^[[36m 2019 Autumn ES 200 3 Basic Sciences BC^[(B^[[m
How can i get this in bash.
I can sort first input by doing sort -k3,4
And the second one by sort -k4,5
But the problem arises when it can be any of the above.
sort? command? here are some samples: sample1, sample2; sample3sortcommands? what do you mean by 'problem arises when it can be any of the above'? what problem are you referring to?sort -k41,60 <file>