linux - Alphanumeric sorting of a string with variable width size -
i stuck in small sorting step. have huge file >300k entries , file has sorted on specific column containing alphanumeric identifiers as
rpl12-8 lrsam1-1 rpl12-9 lrsam1-2 rpl12-10 lrsam1-5 rpl12-11 lrsam1-101 lrsam2-1 act-1 act-100 act-101 act-11
the problem variable width size, unable specify second key identifier (sort -k 1.8n).the first sort on first alphabet, on number next , third number after "-". can enable sorting after "-" using delimiter field don't care width of string.
desired output :
act-1 act-11 act-100 act-101 lrsam1-1 lrsam1-2 lrsam1-5 lrsam1-101 lrsam2-1 rpl12-8 rpl12-9 rpl12-10 rpl12-11
with above data in input.txt:
sort -t- -k1,1 -k2n input.txt
you can change field delimiter -
-t
, sort on first field (as string) -k1,1
, , 2nd field (as number) -k2n
.
Comments
Post a Comment