36.8 lensort: Sort Lines by LengthA nice little script to sort lines from shortest to longest can be handy when you're writing and want to find your big words:
Once I used it to sort a list of pathnames:
The script uses awk (33.11 ) to print each line's length, followed by the original line. Next, sort sorts the lengths numerically (36.5 ) . Then sed (34.24 ) strips off the lengths and the spaces - and prints the lines: #! /bin/sh awk 'BEGIN { FS=RS } { print length, $0 }' $* | # Sort the lines numerically sort +0n -1 | # Remove the length and the space and print each line sed 's/^[0-9][0-9]* //' (Some awk
s require a semicolon after the first curly bracket - that
is, - |
|