Artificial intelligent assistant

Replace single field numbers with double field numbers (1->01) I have the following file, beginning with male 9 male 11 male 9 male 1 female 4 female 13 male 14 If I use sort -u -k1,1 -k2,2n this returns female 13 female 4 male 1 male 11 male 14 male 9 male 9 How can I make the single-digit numbers show as 01, 02, etc. so they will sort correctly? **Update:** The commenter who told me to just move the `-u` to the back was correct. sort -k1,1 -k2,2n -u worked perfectly, thanks!

You haven't defined " _sort correctly_ " anywhere, so I'm going to assume that you want to group by the first column and order by ascending numerical value of the second, with duplicate values removed. This solution isn't what you've actually asked for, but it seems to be what you want.


sort -k1,1 -k2,2n -u datafile
female 4
female 13
male 1
male 9
male 11
male 14


If you really want the second column padded to have two digits you could use this


xargs printf "%s %02d\
" male 09
male 11
male 09
male 01
female 04
female 13
male 14

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 9b3f9680b757e953cefa34f4d78e6278