Sunday, November 22, 2009

AWK - Sort lines from shortest to longest

Display filenames in a directory with the shortest filenames first and longest length last:

ls -1 | awk '{printf "%d\t%s\n", length($0), $0}' | sort +0n -1 | sed 's/^[0-9][0-9]* //'