linux - Bash - Awk sort -n not sorting -


awk '{for(i=1; i<=nf; i++) printf("%d ",$i)}' | sort -n 

it reads file like

55 89 33 20 

and prints out normally, not numerically sorted. why?

sort works on per-line basis, , printf doesn't append newline default, need specify it. use:

awk '{for(i=1; i<=nf; i++) printf("%d\n",$i)}' | sort -n 

this print out numbers on separate lines, if want them in single line again can pipe paste:

awk '{for(i=1; i<=nf; i++) printf("%d\n",$i)}' | sort -n | paste -s -d ' ' 

you can use print instead of printf, append newline default:

awk '{for(i=1; i<=nf; i++) print $i}' | sort -n 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -