I have a file named : newfile which consist of the following data1 AC BB CC2 AB CC DD3 CA BB CC4 BE DD EE5 BD AA AAI type the following command in bash to sort the data according to the second character, second fieldsort -k3 newfileI expected the following results3 CA BB CC2 AB CC DD1 AC BB CC5 BD AA AA4 BE DD EEwhy am i getting the following results and how am i suppose to solve according to the third character (ignoring the blank)5 BD AA AA1 AC BB CC3 CA BB CC2 AB CC DD4 BE DD EE
Sort a text file according to a character within a field
text processing;sort
To sort on a specific character within a field (i.e. a block of character surrounded by blank characters). You can use this specific syntax :sort -k 1.4 fileThis will sort on the fourth character of the file. See https://stackoverflow.com/questions/12383706/unix-sort-on-column-without-separator for details.If you experience counterintuitive results while playing with -k, add the option -b. This will make sort ignore the blanks. Sosort -b -k 2.2 filegives what you want : second character of second field, ignoring blanks.