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
Post a Comment