Bash – sort by not first character

bashsorting

I want to sort my file by first column but I have to start sort from 5 character. How can I do that?

My file:

"TTTTCTTACA"            1       1
"TTTTCTTACC"                    1
"TTTTCTTACT"    1       1
"TTTTCTTAGC"    1
"TTTTCTTATT"                    2
"TTTTCTTCAA"    1               1       1
"TTTTCTTCAG"    1               2       1
"TTTTCTTCAT"            1       2       2
"TTTTCTTCCT"                            2
"TTTTCTTCGG"                    2       2
"TTTTCTTCTA"                            1
"TTTTCTTCTG"            1
"TTTTCTTCTT"    1                       2
"TTTTCTTGAA"            1
"TTTTCTTGCT"    1               1       1
"TTTTCTTTAA"    1
"TTTTCTTTAG"            1       1
"TTTTCTTTCT"    1
"TTTTCTTTGC"    1
"TTTTCTTTGG"            1       1
"TTTTCTTTGT"    1       1       2       1
"TTTTCTTTTA"    1

I was trying:

sort -k1,1 file | uniq -s 6 -w 5 

Of course, it doesn't work. Mayby sort has some flags, but I didn't find them. Do you have some idea?

Best Answer

tl;dr

sort -k1.5 file | uniq -s 6 -w 5


Explanation

My sort is GNU coreutils 8.22. The manpage for my sort shows:

KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and  C
       a  character  position  in  the  field;  both are origin 1, and the stop position defaults to the
       line's end.

So with your current sort command, sort -k1,1 file uses the first word to the first word as the sort.

What you want is (for the sort command anyway):

sort -k1.5 file | uniq -s 6 -w 5

This will use the fifth character of the first word, which is what you wanted.

Related Question